unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdCustomTCPServer, IdContext,
IdTCPServer;
type
TForm1 =
class(TForm)
Button1: TButton;
IdTCPServer1: TIdTCPServer;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
procedure IdTCPServer1Execute(AContext: TIdContext);
procedure IdTCPServer1Connect(AContext: TIdContext);
procedure Button1Click(Sender: TObject);
procedure Log(Msg:
String);
procedure IdTCPServer1Status(ASender: TObject;
const AStatus: TIdStatus;
const AStatusText:
string);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Context: TidContext;
implementation
{$R *.dfm}
procedure TForm1.Log(Msg:
string);
begin
Memo1.Lines.Add('
['+TimeToStr(now)+'
]'+Msg);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
f:
file of byte;
begin
if OpenDialog1.Execute
then
begin
AssignFile(f,OpenDialog1.FileName);
Reset(f);
Log('
Filename: '+ExtractFilename(OpenDialog1.FileName));
Context.Connection.IOHandler.WriteLn(ExtractFileName(OpenDialog1.FileName));
Log('
Filesize: '+IntToStr(FileSize(f)));
Context.Connection.IOHandler.WriteLn(IntToStr(FileSize(f)));
Context.Connection.IOHandler.WriteFile(Opendialog1.FileName,true);
Log('
File transfered');
end;
end;
procedure TForm1.IdTCPServer1Connect(AContext: TIdContext);
begin
Context:=AContext;
Button1.Enabled:=true;
end;
procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
begin
//handle
end;
end.