This Content is from Stack Overflow. Question asked by niCC_S
I am essentially trying to create a web app where one person can start a timer, and everyone else’s timers (on different computers/phones) will start at the exact same time. I am currently using node.js and websockets. When the “master” timer hits start, the server uses websockets to tell all the devices to start. Since all the users should be on the same LAN, I thought I would not have to compensate for latency, but the timers are starting a few hundred milliseconds off of each other, and for my purposes, it is very noticeable. There isn’t much delay between PCs, but mobile phones tend to be the most off of each other.
What would be the best way to get everything to start at the same exact time, within a margin of error of let’s say, 50ms? I do not mind if the timers take a few extra seconds to start if the delay between them is within 50ms.
Send a timestamp to the clients when to start the timer.
Then the accuracy is tied to the accuracy of the system time.
If you can’t ensure that the system time is accurate, another way would be to meassure latency and add it as an offset.
This Question was asked in StackOverflow by niCC_S and Answered by VarChar42 It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.