S
shangjintong
Unregistered / Unconfirmed
GUEST, unregistred user!
请问高手用TClientSocket和TServerSocket如何配合使用进行TStream数据的收发,下面是我的源代码,但不可行,请您指正。(两者已经CONNNCET上)。
//发TStream
procedure TForm1.Button1Click(Sender: TObject);
var
dm:TMemoryStream;
begin
dm:=TMemoryStream.Create;
image1.Picture.Bitmap.SaveToStream(dm);
dm.Position:=0;
ClientSocket1.Socket.SendStream(dm);
dm.Free;
end;
//收TStream
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
dm:TMemoryStream;
begin
dm:=TMemoryStream.Create;
Socket.ReceiveBuf(dm,Socket.ReceiveLength);
image2.Picture.Bitmap.LoadFromStream(dm);
dm.Free;
end;
//发TStream
procedure TForm1.Button1Click(Sender: TObject);
var
dm:TMemoryStream;
begin
dm:=TMemoryStream.Create;
image1.Picture.Bitmap.SaveToStream(dm);
dm.Position:=0;
ClientSocket1.Socket.SendStream(dm);
dm.Free;
end;
//收TStream
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
dm:TMemoryStream;
begin
dm:=TMemoryStream.Create;
Socket.ReceiveBuf(dm,Socket.ReceiveLength);
image2.Picture.Bitmap.LoadFromStream(dm);
dm.Free;
end;