I need to measure the elapsed time between sending a frame and receiving a frame.
You do not need accurate timestamps for this. You can average the expected delay.
If A sends a packet (or frame) to B, B responds immediately (*) :
A (sendTime) ---> B ---> A (receivedTime)
you can easily calculate the delay:
latency = (receivedTime - sendTime) / 2
This suggests, of course, that latency is symmetrical. You can find more complex algorithms if you research the phrases "network latency estimation algorithm."
Having a calculated delay, you can, of course, estimate the time difference (but this does not seem necessary):
A (sendTime) ---> B (receivedTimeB) - (receivedTimeB) → A
timeDelta = sendTime + latency - receivedTimeB
Note that even if you average a lot of results, this algorithm is probably very biased. This is just published as a simple example of a general idea.
(*) The fact that this does not happen really causes an error right away, of course. It depends on how busy machine B.
Bartoszkp
source share