Multi-threaded ping application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to write a ping application that uses multiple threads to ping numerous hosts. I have copied the code from KB 828993 ( http://support.microsoft.com/default.aspx?scid=kb;EN-US;828993 ). This works fine, however I added code to ensure that #1 - the response type is a ping echo (to ensure it wasn't a TTL expired, etc...), and I implemented the Identifier code (currently it uses only 45). This works fine if I use only one thread and run it synchronously. However, if I run it with multiple threads, I get packets that seem crossed. Here's an example:

Host: 1.1.1.1
Sent Packet ID (using Socket.SentTo): 5000
Received Packet ID (using Socket.ReceiveFrom): 9000

Host: 2.2.2.2
Sent Packet ID (using Socket.SentTo): 9000
Received Packet ID (using Socket.ReceiveFrom): 5000

It appears the packets get crossed. I have solved this using BeginReceiveFrom/EndReceiveFrom, but it seems like there should be an explanation as to why I would be receiving the packet from ReceiveFrom that I sent to another host. I have also tried sending the remote hosts' end point to the ReceiveFrom, and I still get the same problem.

Does anyone know why this is or has anyone run into this same problem?
 
Back
Top