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:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Sockets, IdTCPServer, IdContext, StdCtrls, IdThreadComponent;
type TForm1 = class(TForm) ListBox1: TListBox; procedure IdTCPServer1Execute(AContext: TIdContext); procedure IdTCPServer1Connect(AContext: TIdContext); procedure IdTCPServer1Disconnect(AContext: TIdContext); procedure IdTCPServer1Exception(AContext: TIdContext; AException: Exception); procedure FormCreate(Sender: TObject); private public end;
var Form1: TForm1; IdTCPServer1: TIdTCPServer;
implementation
{$R *.dfm}
procedure TForm1.IdTCPServer1Execute(AContext: TIdContext); begin ListBox1.Items.Add('Execute!'); AContext.Connection.SendCmd('Hello World'); end;
procedure TForm1.IdTCPServer1Connect(AContext: TIdContext); begin ListBox1.Items.Add('Connect!'); AContext.Connection.SendCmd('Hello World<br>'); end;
procedure TForm1.IdTCPServer1Disconnect(AContext: TIdContext); begin ListBox1.Items.Add('Disconnect!'); AContext.Connection.SendCmd('Hello World<br>'); end;
procedure TForm1.IdTCPServer1Exception(AContext: TIdContext; AException: Exception); begin ListBox1.Items.Add('Exeception!'); AContext.Connection.SendCmd('Hello World'); end;
procedure TForm1.FormCreate(Sender: TObject); begin IdTCPServer1 := TIdTCPServer.Create(self);
IdTCpServer1.TerminateWaitTime := 1000; IdTCpServer1.MaxConnections := 0; IdTCPServer1.DefaultPort := 6500; IdTCPServer1.OnException := IdTCPServer1Exception; IdTCPServer1.OnExecute := IdTCPServer1Execute; IdTCPServer1.OnConnect := IDTCpServer1Connect; IdTCPServer1.OnDisconnect := IdTCpServer1Disconnect;
IdTCPServer1.Active := True; end;
end. |