I'm working on online game and have client and server. For client I use Unity3D and C#, server is written in C#. For synchronization I use timers, and as we know timers depends from ticks. Ticks counter in C# is class Stopwatch, and count of ticks in 1 second equals Stopwatch.Frequency, but on server and client, values of Stopwatch.Frequency are different, and it kills my synchronization because the timer on server too slow unlike a timer on the client. Stopwatch.Frequency on the server equals 3.124.980, and Stopwatch.Frequency on the client equals 10.000.000. So why??? How i can change the value of Stopwatch.Frequency for timers synchronization? Thanks and sorry for my bad English
Stopwatch
can be unreliable on a PC with multiple processors, or processors that do not have a constant clock speed (processors that can reduce clock to conserve energy), so you simply can't use it in a game (because you want it to work in every computer).
Many games uses a global watch, and I've seen that even the simplest global watch algorithm can be good enough to synchronize clients with a server for a game. Take a look at the Cristian's algorithm.
Having a global watch, you can simply use DateTime.UtcNow
to measure time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With