This project is read-only.

Long latency between device responding & interrupt method activating

Feb 11, 2014 at 12:01 PM
Edited Feb 11, 2014 at 12:09 PM
Hi,

I'm using PcapDotNet for sending/receiving ethernet (commands) packets to a device, for each command packet that I send the card should immediately respond with an acknowledge packet.

The problem is that there is a long latency between the time that the card sends me the response packet, and untill the interrupt method in my application code is activating.

(I'm using Visual Studio 2010 C#)

When I'm looking at the WireShark I see only about 20-30 milliseconds delay between sending my packet (command) and till I'm getting the response from the device, but when I'm measuring in my code the time that passed between finish sending the command and till the method is jumping I see about 700-950 milliseconds delay.

Why am I not getting the interrupt immediately when the device is sending me the response packet ? what is the best way to minimize the delay ?

Also, is there any example code for both sending and recieving packets ?

I can find only code for PcapDotNet-sending, or PcapDotNet-recieving, but not both in the same application, I could use it as a reference.

Thanks!
Feb 15, 2014 at 10:45 AM
Hi Sam2014,

Can you share the code you use for receiving the packets?
You might want to lower the readTimeout you use when you call PacketDevice::Open().

Boaz.
Feb 16, 2014 at 9:04 AM
Edited Feb 16, 2014 at 2:04 PM
Brickner wrote:
Hi Sam2014,

Can you share the code you use for receiving the packets?
You might want to lower the readTimeout you use when you call PacketDevice::Open().

Boaz.
.
Thanks very much Boaz!

I changed the readTimeout as you suggested, and it looks much better now :-) Now I'm getting only about 30-50 milliseconds delay between transmit and recieve.

Before, my Open() command looked like this:
_communicator = device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000);
now I changed it to:
_communicator = device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1);
But how could it solve my latency problem ? the device DID responded, so why did the PcapDotNet waited the timeout ?

Also, what's the meaning of the first parameter in the Open() method, should I change it also ?

Thanks.
Feb 21, 2014 at 8:18 AM
Regarding the first parameter, as stated in the documentation: "Length of the packet that has to be retained. For each packet received by the filter, only the first 'snapshotLength' bytes are stored in the buffer and passed to the user application. For instance, snaplen equal to 100 means that only the first 100 bytes of each packet are stored."

WinPcap holds a buffer of packets, and when it doesn't get full it will wait for the timeout.
The timeout is basically a tradeoff between handling a large amount of packets per second (which without a buffer will make you lose packets) and the latency of seeing packets when the rate is low.

Boaz.
Feb 23, 2014 at 12:04 PM
Now it's much clearer, thanks very much !