TNotifyConnectionResult =
procedure(
const AIp:
string;
const AErrorCode: Integer;
const AInstance: TTestConnection)
of object;
TTestConnection =
class
private
FClientSocket: TWSocket;
FNotifyEvent: TNotifyConnectionResult;
procedure OnClientSessionConnected(Sender: TObject; ErrCode: Word);
public
procedure TestConnection(
const AIp:
string;
const ANotifyEvent: TNotifyConnectionResult);
end;
TTestForm =
class
private
FListOfIpAddresses: TStringList;
procedure NotifyConnectionResult(
const AIp:
string;
const AErrorCode: Integer;
const AInstance: TTestConnection);
procedure TestAllConnections;
end;
implementation
procedure TTestConnection.TestConnection(
const AIp:
string;
const ANotifyEvent: TNotifyConnectionResult);
begin
FNotifyEvent := ANotifyEvent;
FClientSocket.Addr := AIP;
FClientSocket.Port := cDefaultPort;
//oder Port mitgeben
FClientSocket.OnSessionConnected := OnClientSessionConnected;
FClientSocket.Connect;
end;
procedure TTestConnection.OnClientSessionConnected(Sender: TObject; ErrCode: Word);
begin
FNotifyEvent(FClientSocket.Addr, ErrCode, Self);
//Code 0: Verbunden, sonst Fehler
end;
//----
procedure TTestForm.TestAllConnections;
var
IP:
string;
Test: TTestConnection;
begin
for IP in FListOfIpAddresses
do
begin
Test := TTestConnection.Create;
Test.TestConnection(
IP, NotifyConnectionResult);
end;
end;
procedure TTestForm.NotifyConnectionResult(
const AIp:
string;
const AErrorCode: Integer;
const AInstance: TTestConnection);
begin
if AErrorCode = 0
then
//Erfolgreiche Verbindung anzeigen
else
//Verbindung fehlgeschlagen anzeigen
AInstance.Free;
end;