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.