Y
yxylwt
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是接收的部分代码:
procedure TMainForm.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
MyBuffer: array[0..10000] of byte;
S: string;
Len:Integer;
begin
if MySize = 0 then
begin
S := Socket.ReceiveText;
MySize := Strtoint(S);
Socket.SendText('Ready');
end
else begin
Len := socket.ReceiveLength;
StatusBar1.SimpleText := '正在接收数据,数据大小为:' + IntToStr(MySize);
Socket.ReceiveBuf(MyBuffer, len);
Stream.Write(MyBuffer, len);
//Socket.ReceiveBuf(MyBuffer, socket.ReceiveLength);
//Stream.Write(MyBuffer, socket.ReceiveLength);
//注意:上面的代码改为注释掉的代码,效果不一样,真是奇怪!
if Stream.Size >= MySize then
begin
Stream.Position := 0;
Stream.SaveToFile('e:/data.xml');
MySize := 0;
end;
end;
end;
procedure TMainForm.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var
MyBuffer: array[0..10000] of byte;
S: string;
Len:Integer;
begin
if MySize = 0 then
begin
S := Socket.ReceiveText;
MySize := Strtoint(S);
Socket.SendText('Ready');
end
else begin
Len := socket.ReceiveLength;
StatusBar1.SimpleText := '正在接收数据,数据大小为:' + IntToStr(MySize);
Socket.ReceiveBuf(MyBuffer, len);
Stream.Write(MyBuffer, len);
//Socket.ReceiveBuf(MyBuffer, socket.ReceiveLength);
//Stream.Write(MyBuffer, socket.ReceiveLength);
//注意:上面的代码改为注释掉的代码,效果不一样,真是奇怪!
if Stream.Size >= MySize then
begin
Stream.Position := 0;
Stream.SaveToFile('e:/data.xml');
MySize := 0;
end;
end;
end;