- Home /
How to measure network packet delay?
So my previous networking was done in XNA on Xbox Live, and their networking API included some built-in measures of latency (NetworkGamer.RoundTripTime for example). I'm assuming they can do this by using the Xbox Live servers... somehow.
I'm using Photon Networking now and I'm wondering how to get this, or any other reasonable approximation of latency from one player to another. I'm guessing there's no simple API call, so I'm prepared to do it myself - I just would like to figure out a good way how.
My google searches for "game networking latency measurement" and similar haven't led me to any concrete algorithm or anything. I remember once learning about NTP and I suppose I could do this to sync everyone's game clocks, then I could trivially measure latency by adding a timestamp to each packet.
Is this a good way to go about it, or is there something simpler, or is my solution missing something important?
Thank you for any help
Send a network message, asking for a reply, and keep the time you sent it at. On the reply, subtract the time you kept from the current time and you have your latancy.
That's pretty much what NTP does, but also accounting for remote host's processing time. I do want to avoid having to AC$$anonymous$$ every msg received, and also want to track changes in the latency over time. But I guess after initially syncing the clocks with a few rounds of this at the start of the game, I can assume everyone's internal clock runs at the 'correct' speed and I can infer the latency from just a timestamp on each packet. I still don't know if it's the best mix of precision and bandwidth conservation though...