红
红蜻蜓
Unregistered / Unconfirmed
GUEST, unregistred user!
我在使用Tserversocket接收Tclientsocket发送的流数据时,总是出错,请教大侠如何解决!
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
MyRecord : TMyRecord;
fStream : TMemoryStream;
begin
fStream := TMemoryStream.Create;
fStream.SetSize(Socket.ReceiveLength); //按接收数据大小设置流的大小
Socket.ReceiveBuf(fStream,Socket.ReceiveLength); //把接收数据放入流中
fStream.Read(MyRecord,fStream.Size); //把流中数据读入变量中 {出错位置}
edit1.Text := datetimetostr( MyRecord.datetime );
edit2.Text := MyRecord.data;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
MyRecord : TMyRecord;
fStream : TMemoryStream;
begin
fStream := TMemoryStream.Create;
fStream.SetSize(Socket.ReceiveLength); //按接收数据大小设置流的大小
Socket.ReceiveBuf(fStream,Socket.ReceiveLength); //把接收数据放入流中
fStream.Read(MyRecord,fStream.Size); //把流中数据读入变量中 {出错位置}
edit1.Text := datetimetostr( MyRecord.datetime );
edit2.Text := MyRecord.data;
end;