This is a question that I'm curious about, for perfectionism sake. It's not a problem that I'm completely stuck on.
I have a webpage that enables me to set a countdown timer. This countdown timer runs on the server, so an action can be executed when the timer finishes, even if the webpage has been closed.
I suspected it would be as simple as sending the endtime for the timer to the server, getting the current time on the server, set a timeout (NodeJS), and that's it. However, when I do this, the timer on the server finishes about 1.5 seconds before the one on the webpage, consistently. Like I said, this is not a big problem at all, but it made me wonder.
Something else I thought of, while thinking about this problem, was calculating the difference in time between now and the endtime on the webpage, sending this delta to the server, and setting a timeout with this delta. For my case (LAN only), I think this would pretty much "fix" the issue, since I don't expect any network hickups on my LAN. However, when something does go wrong, the timers obviously would be completely out of wack.
So how can I get these two timers "perfectly" synced?