Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Indy - Multi-thread Ping code?

1,025 views
Skip to first unread message

Kasper Kruse

unread,
Aug 5, 2003, 3:23:46 AM8/5/03
to
Hi Friends.

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

Francois PIETTE

unread,
Aug 5, 2003, 4:39:54 AM8/5/03
to
There is a multithreaded ping sample (PINGTHRD.ZIP) available on the
"usermade" page at http://www.overbyte.be.

--

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...

Sebastien DOLARD

unread,
Aug 5, 2003, 5:38:15 AM8/5/03
to
Kasper Kruse wrote:

> 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.

/--------------

Lukas Gebauer

unread,
Aug 5, 2003, 5:40:12 AM8/5/03
to
Francois PIETTE wrote:
> There is a multithreaded ping sample (PINGTHRD.ZIP) available on the
> "usermade" page at http://www.overbyte.be.

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.

Kasper Kruse

unread,
Aug 5, 2003, 6:46:23 AM8/5/03
to
Thank you very much for both of your answers.

Buy the Francois, thank you making some great VCL's.

You saved my day.

- Regards Kasper

0 new messages