Reputation: 370
I have been thinking about this: Send a "message" to the client and then whenever the server receives it i compare the send date with the receive one and then i'll get the ms out of there.
But my question is, Is there any other efficient way to do this?
Upvotes: 1
Views: 4615
Reputation: 570
As for the basic concept:
Simply send out a signal ( like a ping ) and wait till it returns. The execution time tells you the latency between server and client.
It is, however, something you need to do quite often to get an accurate value. The problem being that network latency is highly variable.
Then again, doing this might not be viable at all, since there is more involved than just sending and receiving the signal. For instance, the actual route a packet might take can vary.
Also, one would think that dividing the execution time by 2 results in an accurate result, but it does not.
Server to client might be faster than the return trip, screwing up the results.
Upvotes: 2