I am writing a small program for testing network response time.
I need to ping at least 254 different IP addresses and measure the response
time, I know how to do this one host at the time but it takes ages, can
someone help me with a simple source code example where you can ping 10 host
at the time (and then the next 10 etc) using a threading.
I have no experience with writing threaded applications so please bare over
with me, I am using the TIdIcmpClient from Indy for the ping routine.
Hope you can help me out.
Regards Kasper
--
Contribute to the SSL Effort. Visit
http://overbyte.delphicenter.com/eng/ssl.html
--
francoi...@overbyte.be
The author for the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be
"Kasper Kruse" <k...@checksum.dk> a écrit dans le message de
news:3f2f...@newsgroups.borland.com...
> Hi Friends.
Hi,
here it is, My own product.
/--------------
unit OPingThread;
interface
uses
Classes, IdIcmpClient;
type
TPingNotify = procedure (AHost: string; ClientStatus: TReplyStatus)
of object;
TPingThread = class(TThread)
private
FIcmpClient: TIdIcmpClient;
FRunning: boolean;
FOnAfterPing: TPingNotify;
FHost: string;
{ Send result of ping to display it. }
procedure DoAfterPing;
protected
procedure Execute; override;
public
{ Thread that ping a TCllient host and send result to APingNotifyProc }
//constructor Create(Host: TClient; APingNotifyProc: TPingNotify);
reintroduce;
constructor Create(Host: string; APingNotifyProc: TPingNotify);
reintroduce;
destructor Destroy; override;
property Running: boolean read FRunning write FRunning;
property OnAfterPing: TPingNotify read FOnAfterPing write FOnAfterPing;
end;
implementation
uses
SyncObjs;
{ TPingThread }
constructor TPingThread.Create(Host: string; APingNotifyProc: TPingNotify);
begin
inherited Create(True);
FreeOnTerminate := True;
FIcmpClient := TIdIcmpClient.Create(nil);
//FIcmpClient.Host := Host.Address;
FIcmpClient.Host := Host;
FHost := Host;
FOnAfterPing := APingNotifyProc;
FRunning := false;
Resume;
end;
destructor TPingThread.Destroy;
begin
FIcmpClient.Free;
inherited;
end;
procedure TPingThread.DoAfterPing;
begin
if Assigned(FOnAfterPing) then
FOnAfterPing(FHost, FIcmpClient.ReplyStatus);
end;
procedure TPingThread.Execute;
var
doesPing: boolean;
nbPing: integer;
begin
doesPing := true;
nbPing := 0;
FRunning := true;
while not Terminated do
begin
FIcmpClient.Ping;
Inc(nbPing);
if (FIcmpClient.Host = FIcmpClient.ReplyStatus.FromIpAddress) and
(FIcmpClient.ReplyStatus.BytesReceived > 0) then
doesPing := false;
if (not doesPing) or (nbPing > 3) then
Terminate;
end;
FRunning := false;
Synchronize(DoAfterPing);
end;
end.
/--------------
For Synapse too. :-) (in Synapse's demos is sample for multithreaded
network scan by my Ping implementation.)
And my implementation of Ping working with IPv6 too. ICS or Indy not, as
I know! ;-)
--
Lukas Gebauer.
http://www.ararat.cz/synapse/ - Synapse Delphi and Kylix TCP/IP Lib.
Buy the Francois, thank you making some great VCL's.
You saved my day.
- Regards Kasper