1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78:
| 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 procedure OnConnect(AContext: TIdContext); public Server: TIdTCPServer; procedure Log(Text: String; Farbe: Byte = 0); end;
var Main: TMain;
implementation
{$R *.dfm}
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. |