unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ScktComp;
type
TForm1 =
class(TForm)
ServerSocket1: TServerSocket;
Memo1: TMemo;
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
procedure ServerSocket1ClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if not(ServerSocket1.Active)
then begin
ServerSocket1.Port := StrToInt(Edit1.Text);
ServerSocket1.Active := true;
Memo1.Lines.Add('
Server wurde gestartet..');
Button1.Caption := '
Stop';
end
else begin
ServerSocket1.Active := false;
Memo1.Lines.Add('
Server wurde gestoppt..');
Button1.Caption := '
Start';
end;
end;
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
var
i: integer;
msg:
string;
begin
msg := '
Neuer Client ('+Socket.RemoteHost+'
||'+Socket.RemoteAddress+'
) ist verbunden';
for i := 0
to ServerSocket1.Socket.ActiveConnections - 1
do begin
with ServerSocket1.Socket.Connections[i]
do begin
SendText(MSG);
Memo1.Lines.Add('
Debug: ClientConnected - ' + IntToStr(i) + '
-' + MSG);
end;
end;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
i:integer;
msg:
string;
begin
msg := Socket.RemoteHost+'
||'+Socket.RemoteAddress+'
) ' +Socket.ReceiveText;
for i := 0
to ServerSocket1.Socket.ActiveConnections-1
do begin
ServerSocket1.Socket.Connections[i].SendText(msg);
Memo1.Lines.Add('
Debug: ClientRead - ' + IntToStr(i) + '
- ' +msg);
end;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
var
i:integer;
msg:
string;
begin
for i := 0
to ServerSocket1.Socket.ActiveConnections - 1
do begin
with ServerSocket1.Socket.Connections[i]
do if (Connected)
then SendText('
Client ('+Socket.RemoteHost+'
||'+Socket.RemoteAddress+'
) hat die Verbindung getrennt');
end;
end;
procedure TForm1.ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
var
i:integer;
begin
//for i := 0 to ServerSocket1.Socket.ActiveConnections - 1 do begin
//with ServerSocket1.Socket.Connections[i] do if (Connected) then SendText('Client ('+Socket.RemoteHost+'||'+Socket.RemoteAddress+') hat die Verbindung getrennt - ('+IntToStr(ErrorCode)+')');
//end;
end;
procedure TForm1.ServerSocket1ClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
var
i:integer;
begin
//for i := 0 to ServerSocket1.Socket.ActiveConnections - 1 do begin
//with ServerSocket1.Socket.Connections[i] do if (Connected) then SendText('('+Socket.RemoteHost+'||'+Socket.RemoteAddress+') ' +Socket.ReceiveText);
//end;
end;
end.