728883902
728883902

Reputation: 507

Is client-side time-keeping likely to be consistent vs server-side time keeping?

I am building a game wherein two users compete against the clock. Each player has 60 seconds to answer as many questions correctly as possible.

I have two potential approaches to time-keeping:

  1. Send the time remaining from the server to the client every second - using Socket.io, wasteful of server resources
  2. Handle the countdown on the client side, but send a signal from the server to terminate the game after 60 seconds - possible that the countdown for each player would not be synchronised

My question is this: would a client-side countdown be reasonably consistent between both clients?

If implemented client-side, it would be using setInterval() in JavaScript.

Upvotes: 3

Views: 846

Answers (1)

Kunok
Kunok

Reputation: 8769

Your real state should be held on the server while clients should try to sync (update thier state) depending on server response state. Basically, if user gets lag, he still loses his time, rather than blocking time. This also prevents client-side cheats by changing values.

So on each tick, your clients should know what is the real time from the server.

Upvotes: 2

Related Questions