C
cuit421
Unregistered / Unconfirmed
GUEST, unregistred user!
程序实现客户端发送一副图片到服务端。程序如下:
客户端
procedure TForm1.BitBtn1Click(Sender: TObject);
var
tem:Tmemorystream;
begin
idtcpclient1.Host:=edit1.Text;
tem:=tmemorystream.Create;
image1.Picture.Graphic.SaveToStream(tem);
idtcpclient1.Connect();
idtcpclient1.WriteStream(tem);
idtcpclient1.Disconnect; //问题所以????????
end;
服务端
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
t:Tmemorystream;
myjpg:tjpegimage;
begin
myjpg:=tjpegimage.Create;
t:=tmemorystream.Create;
athread.Connection.ReadStream(t,-1,true);
t.Position:=0;
myjpg.LoadFromStream(t);
image1.Picture.Bitmap.Assign(myjpg);
end;
以上程序正常
问题是客户端必须发送完后加一句idtcpclient1.Disconnect;如果不加就不能正常接收到,不知是什么原因?高手给讲讲。我想实现的是,连接一次后传输几次图片后再断口,省的每次都连接。
客户端
procedure TForm1.BitBtn1Click(Sender: TObject);
var
tem:Tmemorystream;
begin
idtcpclient1.Host:=edit1.Text;
tem:=tmemorystream.Create;
image1.Picture.Graphic.SaveToStream(tem);
idtcpclient1.Connect();
idtcpclient1.WriteStream(tem);
idtcpclient1.Disconnect; //问题所以????????
end;
服务端
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
t:Tmemorystream;
myjpg:tjpegimage;
begin
myjpg:=tjpegimage.Create;
t:=tmemorystream.Create;
athread.Connection.ReadStream(t,-1,true);
t.Position:=0;
myjpg.LoadFromStream(t);
image1.Picture.Bitmap.Assign(myjpg);
end;
以上程序正常
问题是客户端必须发送完后加一句idtcpclient1.Disconnect;如果不加就不能正常接收到,不知是什么原因?高手给讲讲。我想实现的是,连接一次后传输几次图片后再断口,省的每次都连接。