T
ttt22703
Unregistered / Unconfirmed
GUEST, unregistred user!
如果在接收客户端的文件小的话,一般没有什么问题,但有是在接收时出现 "is not a valid integer value",有时出一次,有时出好几次不知道哪里出了错代码如下,希望各位前辈给与指正.谢谢
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
temp:tstringlist;
str:string;
buffer:array [0..10000] of byte;
len:integer;
begin
if c=0 then
begin
str:=socket.ReceiveText ;
temp:=tstringlist.Create ;
temp.Text :=str;
c:=strtoint(temp.Values['size']);
filename:=temp.Values['filename'];
memo1.Lines.Add(filename+'长度'+inttostr(c));
temp.Free;
socket.SendText('准备接收');
end
else
begin
//''''开始读取流'
len:=socket.ReceiveLength ;
socket.ReceiveBuf(buffer,len);
m.Write(buffer,len);
//memo1.Lines.Add(filename+'--------'+inttostr(len));
if m.Size >=c then
begin
m.Position :=0;
try
m.SaveToFile('c:/temp/'+filename);
finally
m.Clear ;
c:=0;
memo1.Lines.Add(filename+'完成!')
end;
end;
end;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
temp:tstringlist;
str:string;
buffer:array [0..10000] of byte;
len:integer;
begin
if c=0 then
begin
str:=socket.ReceiveText ;
temp:=tstringlist.Create ;
temp.Text :=str;
c:=strtoint(temp.Values['size']);
filename:=temp.Values['filename'];
memo1.Lines.Add(filename+'长度'+inttostr(c));
temp.Free;
socket.SendText('准备接收');
end
else
begin
//''''开始读取流'
len:=socket.ReceiveLength ;
socket.ReceiveBuf(buffer,len);
m.Write(buffer,len);
//memo1.Lines.Add(filename+'--------'+inttostr(len));
if m.Size >=c then
begin
m.Position :=0;
try
m.SaveToFile('c:/temp/'+filename);
finally
m.Clear ;
c:=0;
memo1.Lines.Add(filename+'完成!')
end;
end;
end;
end;