Why Pcap.net ReceivePacket has a 1000ms lag?

114 Views Asked by At

I am trying to constantly capture packets using Pcap.Net library and respond to them immediately.

However there is a long periodic lag in the ReceivePacket method.

I have set up a stopwatch before ReceivePacket and stopped it afterwards. The results show 1000ms time elapsed. I also ping the address with ping 1.1.1.3 -t .

while (true)
{
    Packet p;

    Stopwatch sw = new Stopwatch();
    sw.Start();

    var res = nic.ReceivePacket(out p);
    sw.Stop();

    if (res == PacketCommunicatorReceiveResult.Ok)
    {
        Adapter.WriteToBuffer(p.ToArray());
    }

    Debug.WriteLine("Received Packet lag: " + sw.ElapsedMilliseconds.ToString("D"));
}

This is the output:

Received Packet lag: 1000
Received Packet lag: 0
Received Packet lag: 1000
Received Packet lag: 0

... and so on.

0

There are 0 best solutions below