Asynchronous ICMP

  • Thread starter Thread starter Andrew Jones
  • Start date Start date
A

Andrew Jones

I have seen some posts here about asynchronous ICMP and I am having a little
problem with threading.

Here is what I am trying to do.

I have a large number of hosts to ping. Each host is a class, that has a
method running in it's own thread. I send out 10 ICMP packets and call the
socket.BeginReceiveFrom(...) method for each packet sent. The problem is
that the reply packets seem to all queue up and then the asynchronous
receive delegate takes the earliest received packet, regardless of whether
or not that packet is from the same Endpoint that generated the response.
Is there anyway to force the asynchronous delegate to fire only for packets
received from the corresponding endpoint? Ideally each class should only
process the replies that it generated requests for and not replies from
other hosts.

Thanks,
Andrew
 
I don't think you can do that as this is a bit like UDP where you don't have
any predictable order of replies, etc. So you would still need to keep some
kind of state to figure out replies, etc. Another method that would work is
this: Create your ping class to allow seperate instances. In each Host
class, contain and new-up a ping object for just that host. Each Host will
ping their own endpoint on a seperate thread using your own thread pool or
your own pool of worker threads. You could also do this. Create a worker
object, say PingHost, that has a ref to a shared Queue or Array of type
Host. Each PingHost worker will have it own thread and ref to shared Array.
The worker delegate will grab a Host object from the Array or Queue and ping
that Host using its own socket and wait for reply syncronously. You can
have 5, 10, or more workers started depending on your needs. All workers
are the same, so it is easy to start many instances and put their references
in another Array or ArrayList. Few different options here, there are
others. hth
 
Back
Top