самый простой и примитивный способ:
Код:
type
TMyThread = class(TThread)
host: string;
port: integer;
isalive: boolean;
public
procedure ToLog;
protected
procedure Execute; override;
end;
..........................
procedure TMyThread.ToLog;
begin
if isalive then
Form1.Memo1.Lines.Add(host + ' at port ' + IntToStr(port) + ' is alive')
else
Form1.Memo1.Lines.Add(host + ' at port ' + IntToStr(port) + ' is NOT alive');
end;
procedure TMyThread.Execute;
var
IdTCPClient: TIdTCPClient;
begin
isalive := False;
FreeOnTerminate := True;
IdTCPClient := TIdTCPClient.Create(nil);
IdTCPClient.Host := host;
IdTCPClient.Port := port;
try
IdTCPClient.Connect;
if IdTCPClient.Connected then
isalive := True
except
isalive := False;
end;
IdTCPClient.Free;
Synchronize(ToLog);
end;
Код:
var
ping: TMyThread;
i: integer;
begin
for i:=1 to 100 do
begin
ping := TMyThread.Create(True);
ping.host := 'localhost';
ping.port := i;
ping.Resume;
end;