unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp;
type
TForm1 =
class(TForm)
ServerSocket1: TServerSocket;
procedure ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Clienthwnd:
Array[0..1]
of Hwnd;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
ServerSocket1.Active := True;
end;
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
begin
If Socket.Handle = ClientHWND[0]
then
ServerSocket1.Socket.Connections[0].SendText('
hallo')
else
ServerSocket1.Socket.Connections[1].SendText('
hallo');
end;
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
If ClientHWND[0] <> 0
then
begin
ClientHWND[0] := Socket.Handle;
exit;
end else if ClientHWND[1] <> 0
then
Socket.Disconnect(2)
else
ClientHWND[1] := Socket.Handle;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
If socket.Handle = ClientHWND[0]
then
begin
ClientHWND[0] := ClientHWND[1];
ClientHWND[1] := 0;
end else if socket.Handle = ClientHWND[1]
then
ClientHWND[1] := 0;
end;
end.