unit Unit1;
interface
uses
IdTCPServer, IdContext,
Classes, SysUtils, Forms, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
FServer: TIdTCPServer;
procedure Log(
const Msg:
string);
procedure OnConnect(AContext: TIdContext);
procedure OnExecute(AContext: TIdContext);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
FServer.Active := True;
Log('
Server is listening');
Log('
Bindings[0].IP=' + FServer.Bindings[0].IP);
Log('
Bindings[0].Port=' + IntToStr(FServer.Bindings[0].Port));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FServer := TIdTCPServer.Create(Self);
FServer.OnExecute := OnExecute;
FServer.OnConnect := OnConnect;
FServer.DefaultPort := 23;
// Telnet Port
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
FServer.Active := False;
end;
procedure TForm1.Log(
const Msg:
string);
begin
WriteLn(Msg);
// Ausgabe setzt Linken als "Konsolenanwendung" voraus
end;
procedure TForm1.OnConnect(AContext: TIdContext);
begin
Log('
CONNECT');
Log(AContext.Binding.PeerIP);
AContext.Connection.IOHandler.WriteLn('
Welcome to Indy TCP Server example');
Log('
Welcome message sent');
end;
procedure TForm1.OnExecute(AContext: TIdContext);
begin
Sleep(1000);
AContext.Connection.IOHandler.WriteLn('
Bye');
AContext.Connection.Disconnect;
end;
end.