I’ve been working on a piece of my project that needs to synchronize time between clients and servers. My original idea was to make everything use “server time”, and have each client calculate a server time offset at startup by trading packets with the server.
The clients can now recieve a player move event which contains a starting point, direction, and velocity, and using the attached server time adjust the remote players position to reflect it more accurately (since network lag means some time has passed since the event was created).
So I’ve got this mostly working, and it’s calling System.nanoTime() . But I realized in a clustered environment this can be wildly different across nodes of the Cluster.
Are their any suggestions about how I might get what I’m after that will work properly across the cluster?
Should I just use System.currentTimeMillis() since it’s time since January 1, 1970 UTC instead of some arbitrary point that the nanoTime method uses? I could assume all nodes in the cluster were running NTP and had their time synced.
Just curious about your thoughts or if I’m going about this all wrong?