unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, IdTCPServer, IdComponent, IdContext;
type
TMain =
class(TForm)
RichEdit1: TRichEdit;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private-Deklarationen }
procedure OnConnect(AContext: TIdContext);
public
{ Public-Deklarationen }
Server: TIdTCPServer;
procedure Log(Text:
String; Farbe: Byte = 0);
end;
var
Main: TMain;
implementation
{$R *.dfm}
{ TForm1 }
procedure TMain.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown := True;
Server := TIdTCPServer.Create(self);
Server.DefaultPort := 1307;
Server.OnConnect := OnConnect;
end;
procedure TMain.FormDestroy(Sender: TObject);
begin
if (Server.Active)
then
Server.Active := False;
Server.Free;
end;
procedure TMain.Log(Text:
String; Farbe: Byte = 0);
var
aFont: TFont;
begin
aFont := TFont.Create;
aFont.
Name := '
Courier';
aFont.Size := 10;
case Farbe
of
0: aFont.color := clSilver;
1: aFont.Color := clWhite;
2: aFont.Color := clRed;
3: aFont.color := clYellow;
4: aFont.color := clLime;
5: aFont.color := clAqua;
end;
RichEdit1.SelAttributes.Assign(aFont);
RichEdit1.Lines.add(Format('
[%s]: %s',[TimeToStr(now),Text]));
aFont.Free;
end;
procedure TMain.OnConnect(AContext: TIdContext);
begin
with aContext.Binding
do
begin
Log('
Incoming connection from '+PeerIP);
Log('
Checking IP...');
Log('
Connection Accepted from '+PeerIP);
end;
end;
end.