2

Is there way to know precise time when packages arrives to buffer with UDP protocol in C# (windows 7)?

I tried somethings like this:

while(true) {
    UDPclient.Receive(ref remoteEp);
    Console.WriteLine(System.DateTime.Now.TimeOfDay.ToString()); }

I got wrong result. Some of packages arrive very close, some too far from each other. Wireshark gives correct timestamp, time between two packages are the same in my application. I also tried with the asynchronous BeginReceive operation, but I also got wrong timings between packages. I tried to increase thread priority in which I receive, but also didn't solve my problem.

I process packages really fast, so while loop is not too slow (I checked it).

Is there any way to know when packages arrive to buffer instead when are received from buffer?

Shiro
  • 33
  • 5

1 Answers1

1

DateTime.Now has 15ms precision on most machines. You can measure relative times (time spans) very precisely using Stopwatch.

I doubt the NIC driver or anything else in the stack below you is recording precise timestamps for packets. So I think this is the best you can get (except for using WinPcap to capture packets like Wireshark does).

usr
  • 168,620
  • 35
  • 240
  • 369