unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Scktcomp, StdCtrls;
type
TForm1 =
class(TForm)
Server: TServerSocket;
Memo1: TMemo;
Button1: TButton;
procedure ServerClientRead(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure Button1Click(Sender: TObject);
procedure ServerAccept(Sender: TObject; Socket: TCustomWinSocket);
procedure ServerClientError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ServerClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
msg:
string;
begin
server.Socket.
Read(1);
msg := server.Socket.ReceiveText;
memo1.Lines.Add(msg);
end;
procedure TForm1.ServerClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.Lines.Add('
Client connected!!!');
end;
procedure TForm1.ServerClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
memo1.Lines.Add('
Client disconnected!!!');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Server.Active := false;
server.Free;
sleep(500);
Server.Active := true;
server.Open;
end;
procedure TForm1.ServerAccept(Sender: TObject; Socket: TCustomWinSocket);
begin
memo1.Lines.Add('
Accepted');
end;
procedure TForm1.ServerClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
memo1.Lines.Add('
ClientError!');
end;
end.