In my application I have a Server and x Clients. When a Client starts, he obtained the current System time from the Server. Every Client has to work with the Server time and can´t use his own System time.
Now my Question: What is the best way to run a clock on the Client that starts with the current Server time and run nearly synchronous to it without to receive the Server time every x seconds?
The goal is to display a runing clock with the Server time on the client.
The tolerance that the client clock may have is about 1second in 24hours.
In my solution I got a Timer that trigger every 500ms and count 500ms on the Server time when the Timer executes. But this is not a good solution 🙂 because the Client clock differ from the Server time.
Thanks for your reply
I find a Solution that fits perfectly for my situation.
Instead of using
System.currentTimeMillis(), I’m usingSystem.nanoTime().System.nanoTime()is independent from the System clock.When I receive the current Server time, I save additional the ns from the System. Then the current Server time will be calculated with the difference between the ns time from Server time receiving and the current nanoTime plus the Server time.
Example:
Thx