Synchronizing game time on server and client side

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

coder.arun
Posts: 11
Joined: 06 Nov 2019, 06:06

Synchronizing game time on server and client side

Postby coder.arun » 07 Nov 2019, 03:30

I have a game room with scheduled task running for every 2 minutes. When I start the scheduler, I am sending start response to all clients with the remaining time "120" secs which in turn used by all clients to show time ticking rather than polling server every second. But it's possible that some clients with low network receive that response with some lag. I use ping pong lag monitor to calculate the lag but even after restrting my bandwidth to 2 kbps, lag monitor always giving values like 1 or ,50ms, values like that even when the lag is more than 5 secs. How can I make sure that all clients receiving the response at the same time and synchronize with the server.
Can you give me some code samples
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronizing game time on server and client side

Postby Lapo » 07 Nov 2019, 09:27

Hi,
the lag measured by the API's LagMonitor is the time it takes for a packet to go to the server and come back, the so called round-trip time. Reducing the bandwidth does not necessarily affect the lag. For example if you limit the network to 2KB/s but the client is only using 500byte/s it's likely your ping will still be low.

Also the LagMonitor by default pings the server every 4 seconds. To get a more precise lag measurement you may need to make it faster (i.e. every 1 second). However this will also increase the amount of traffic generated by all clients.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
coder.arun
Posts: 11
Joined: 06 Nov 2019, 06:06

Re: Synchronizing game time on server and client side

Postby coder.arun » 07 Nov 2019, 12:01

So how do I suppose to synchronize client and server game room time properly ? Any recommended approach...?

I want to make sure that all clients running time synchronized with server... Even 1 or 2 seconds delay is acceptable... Bit not more than that.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronizing game time on server and client side

Postby Lapo » 07 Nov 2019, 14:47

I would try to sample the lag every 2 seconds via the LagMonitor and see if it helps compensate the user's latency.
Using the SmartFox.enableLagMonitor(bool, int, int) method.
The first param enables it
The 2nd param specifies how many seconds between each ping (default = 4)
The 3rd param specifies the number of samples used to calculate the average (default = 10)

I would recommend using 2 seconds, and maybe using only 4-5 samples.

Let us know
Lapo

--

gotoAndPlay()

...addicted to flash games
coder.arun
Posts: 11
Joined: 06 Nov 2019, 06:06

Re: Synchronizing game time on server and client side

Postby coder.arun » 07 Nov 2019, 16:17

I don't think that will work. I tried that already but not helping.. what i really want to do now is to restrict the player when the bandwidth is less than 1mbps. Is that possible ? Is there any possibility to find the internet speed and kick him out. I know it's outside the scope.. but do you have any experience on this ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronizing game time on server and client side

Postby Lapo » 08 Nov 2019, 07:56

Can you better explain what you've done?
As I mentioned restricting the bandwidth does not necessarily translate in higher latency. It depends on the traffic the client is generating vs the actual state of the network. Also it depends on the physical distance between client and server.

You said with restricted bandwidth you saw low ping times but you had high latency. I am not sure I understand how you tested this exactly. Can you expand?

what i really want to do now is to restrict the player when the bandwidth is less than 1mbps. Is that possible ? Is there any possibility to find the internet speed and kick him out. I know it's outside the scope.. but do you have any experience on this ?

Measuring the client bandwidth requires extra tools that we don't provide. Also I don't think this is common practice in multiplayer games. You'd rather monitor the current latency and give warnings to the player when it's too high.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
coder.arun
Posts: 11
Joined: 06 Nov 2019, 06:06

Re: Synchronizing game time on server and client side

Postby coder.arun » 08 Nov 2019, 11:40

What I mentioned was whether I have 100mbs or 2kbps, I don't see any difference in ping times... That's the problem we are facing right now... We don't have a proper way to identify whether client is very using poor Network or super high speed network.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronizing game time on server and client side

Postby Lapo » 08 Nov 2019, 13:52

What I am asking is... have seen the game struggling in terms of multiplayer smoothness while the measurement of the ping times was perfectly healthy?
If so, have you found specific conditions under which this can be reproduced (game struggling, healthy ping)

I am asking because I'd expect the ping values to be pretty high if the game is struggling, as network congestion would affect ping requests just like any other requests.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
coder.arun
Posts: 11
Joined: 06 Nov 2019, 06:06

Re: Synchronizing game time on server and client side

Postby coder.arun » 08 Nov 2019, 18:46

When are doing two kinds of testing one with usual bandwidth like 50mbps where we don't have any issues at all .. game is smooth receiving response at the right time time and lag like 1 sec is negligible. Here in this case ping lag is like 5millis.
But as soon as we reduce the bandwidth to say. About 25kbps, things are going out of control. Server response receiving after 20secs by that time, next game already scheduled on server side. But here on client side it's 20secs delayed. Here also the ping time is like 5 to 10 milis.. is not going more than 1sec.

So how do we make sure that my game emruns smoothly when there is a drastic network fluctuations.?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronizing game time on server and client side

Postby Lapo » 09 Nov 2019, 07:50

You mean 25 kilobit per second? That's 3KByte/s! :shock:
How many people these days run such a low bandwidth connection? That's like a dial-up modem from 1995. It seems like you're testing a too extreme scenario. No multiplayer game would run under those settings, these days. Not even 10 years ago.

Is this a real time game? What's the packet-per-second rate?
Also is it only TCP? Or TCP + UDP?

You could try measuring the lag in the opposite direction: server send "ping", client replies with a "pong". If the game is lagging that hard it's not possible that ping/pong packets arrive with perfect timing. If that's the case something is wrong in the test settings, or you didn't explain all the variables at play.

So how do we make sure that my game emruns smoothly when there is a drastic network fluctuations.?

Well, normally you don't, unfortunately. This is a common issue for any multiplayer game.
Drastic network fluctuations will affect the game, especially if it's a real-time type of game. For multiplayer games you don't need huge amount of bandwidth (as a client), but you need two things:
1) relative proximity with the server (i.e. a few hundred Km/s)
2) decent connection with stable in/out

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
coder.arun
Posts: 11
Joined: 06 Nov 2019, 06:06

Re: Synchronizing game time on server and client side

Postby coder.arun » 09 Nov 2019, 09:27

:) unfortunately yes. Some of the clients still using it :).
So you mean we have to find the round trip from server sending ping to all clients and get requests from each client and calculate the round trip time of each client and disconnect them from server if there is more lag ?.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronizing game time on server and client side

Postby Lapo » 10 Nov 2019, 16:13

I am not sure why you want to disconnect players with lag.
A momentary slow down is possible even with a decent connection. Unless you're planning to monitor the lag over time the solution you propose doesn't seem very useful.

Why not letting the player decide if they want to play or not? And how would you recognize a persisting latency from an intermittent one? Kicking them out of the game sounds like the worst of choices. Instead you could just give them a warning that their connection is not optimal and let them decide whether or not they want to keep playing.

Also I will say one more time that the 3KB/s idea is just insane :) No offense. I might understand if you were referring to 3KB/s as the minimum amount of bandwidth for the game alone, but 3KB/s for the whole network does not make any sense.
Lapo

--

gotoAndPlay()

...addicted to flash games
coder.arun
Posts: 11
Joined: 06 Nov 2019, 06:06

Re: Synchronizing game time on server and client side

Postby coder.arun » 10 Nov 2019, 16:37

Yes warning is right choice.. but the lag calculation I can go with server sending ping to clients and clients sending request back to server right ?
On what frequency I check this ?
Do you have any code samples to do this ?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Synchronizing game time on server and client side

Postby Lapo » 11 Nov 2019, 08:41

I suggested measuring from server side because you said the client side LagMonitor doesn't report what you expect.
However I also told you that I find it very strange that you see super slow interactions while the ping reports very low latency, because I would expect everything to be slow, but you didn't provide any details as to what protocols you're using (tcp/udp), what kind of game you're developing (realtime vs turn based) and what's the packet rate.

This is to say I can't guarantee that measuring from server side will make a difference, as I don't even understand exactly what you're doing.

On what frequency I check this ?

Between 1-4 seconds

Do you have any code samples to do this ?

Sorry no, but it's very simple. Send an empty Extension request called "Ping" (or whatever) from server side and store the current time for that User. Then reply from the client with a "Pong" and on the server side subtract the previous time from the current time (using System.nanoTime())

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 56 guests