unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdTCPServer, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
IdTCPClient1: TIdTCPClient;
IdTCPServer1: TIdTCPServer;
Panel1: TPanel;
procedure Button1Click(Sender: TObject);
procedure IdTCPServer1Execute(AThread: TIdPeerThread);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Stream: TFileStream;
begin
if OpenDialog1.Execute then
Stream := TFileStream.Create(OpenDialog1.FileName, fmCreate);
IdTCPClient1.Host := '127.0.0.1';
IdTCPClient1.Port := 7000;
IdTCPServer1.Active := True;
IdTCPClient1.Connect;
try
IdTCPClient1.WriteStream(Stream, True, True, 0);
finally
Stream.Free;
end;
end;
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
EingangsStream: TFilestream;
begin
if SaveDialog1.Execute then
EingangsStream := TFileStream.Create(SaveDialog1.FileName, fmCreate);
try
Athread.Connection.ReadStream(EingangsStream);
finally
EingangsStream.Free;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if IdTCPClient1.Connected then
IdTCPClient1.Disconnect;
if IdTCPServer1.Active then
IdTCPServer1.Active := False;
end;
end.