Tcp
program fserver;{$APPTYPE CONSOLE}
uses
SysUtils,
IdTCPServer,
IdThreadMgrDefault,
IdStatus, Sockets;
type
TTCPclass = class
Public
procedure onExecute(AThread: TIdPeerThread);
procedure onConnect(AThread: TIdPeerThread);
procedure onDisconnect(AThread: TIdPeerThread);
end;
var
TCP : TIdTCPServer;
ITMgr : TIdThreadMgrDefault;
port : integer;
resbuffer, sendbuffer, cmdline : string;
TCPc : TTCPclass;
Procedure TTCPclass.onExecute(AThread: TIdPeerThread);
begin
sendbuffer := 'Pong';
writeLn(AThread.Connection.ReadLn(#0));
AThread.Connection.writeLn(sendbuffer+#0);
AThread.Connection.disconnect;
readLn;
end;
Procedure TTCPclass.onConnect(AThread: TIdPeerThread);
begin
writeLn('Client Connected...');
readLn;
end;
Procedure TTCPclass.onDisconnect(AThread: TIdPeerThread);
begin
writeLn('Client Disconnected...');
readLn;
end;
procedure readline(line: String);
begin
if (line = 'quit') then
begin
exit;
end;
TCP.OnExecute := TCPc.onExecute;
TCP.OnConnect := TCPc.onConnect;
TCP.OnDisconnect := TCPc.onDisconnect;
readLn(cmdLine);
readline(cmdLine);
end;
begin
WriteLn('-------------------------------');
WriteLn(' PleXzel Chat Server Build 0.1 ');
WriteLn('-------------------------------');
WriteLn('');
Write('Server Port: ');
Readln(port);
TCPc := TTCPclass.Create();
TCP := TIdTCPServer.Create(nil);
TCP.DefaultPort := port;
TCP.TerminateWaitTime := 5000;
TCP.Active := true;
TCP.OnExecute := TCPc.onExecute;
TCP.OnConnect := TCPc.onConnect;
TCP.OnDisconnect := TCPc.onDisconnect;
WriteLn('');
WriteLn('Server Running');
readLn(cmdLine);
readline('cmdline');
TCPc.Free;
end.