发送端
procedure TForm1.Button2Click(Sender: TObject);
var
buf:tfilestream;
begin
buf := TFileStream.Create(edit5.Text, fmOpenRead);//edit5.text文件名(含路径)
IdTCPClient1.Host:=edit1.Text;//ip string;
IdTCPClient1.Port:=1053;
IdTCPClient1.Connect();
IdTCPClient1.WriteLn(ExtractFileName(edit5.Text));
IdTcpClient1.WriteStream(buf,true,true);
//发送文件
IdTcpClient1.Disconnect;
buf.Free;
end;
接收端
procedure Tfm_main.IdTCPServer1Execute(AThread: TIdPeerThread);
var
buf: TFileStream;
FileName:string;
size:longint;
begin
// IdTCPServer1.Bindings:='0.0.0.0:1053'
// IdTCPServer1.active:=true;
//预先在属性设置好
FileName:=athread.Connection.ReadLn;
buf := TFileStream.Create(FileName, fmCreate);
AThread.Connection.ReadStream(buf, -1, true);
buf.Free;
end;