I\'m trying to create a multiplayer game with NodeJS and I want to synchronize the action between clients.
What would be the best way to find the latency (the time that
What I usually do to send timestamp with request:
new Date()
and send timestamp: date.getTime()
to the server, with every JSON request.processed: (new Date()).getTime()
in the object.timestamp
from the request, and a new processed field: processed: (new Date()).getTime() - req.processed
that now contains the number of milliseconds it took to process the request.timestamp
(which is the same that was sent on pt 1) and subtract it from the current time, and subtract processing time (processed
), and there is your "real" ping time in milliseconds.I think you should always include the time for both request and response in the ping time, even if there is one-way communication. This is because that is the standard meaning behind "ping time" and "latency". And if it is one-way communication and the latency is only half of the real ping time, that's just a "good thing".