getting Different Time per client if used getServerTime from loadbalancing client

Options
Hi ,

I want to use the server time in game at client to synchronize the custom events but the time at multiple clients are different .

Some times i am getting the expected Time ( same time ) on multiple clients but most of the time I am getting different values in milliseconds

so please help me to get the same time when I call the getServerTime Api on any client at the same time

Comments

  • Kaiserludi
    Options
    Hi @Harish_Kagale.

    How much do the times differ? Just a few milliseconds? That is expected.
    The accuracy of the server time depends on a low jitter (the jitter is how much the latency varies).
    The server can only send it timestamp at the moment when it sends out a message to the client, but can't know when exactly that message will arrive, while the client only knows the client time at the exact moment when the servers messages arrives, but can't know the exact time at which it has been sent. Therefor the client adds the round trip time on top to account for the latency.
    Unfortunately latency usually isn't a constant, but varies, especially shortly after establishing a connection.
    You can call PhotonPeer::fetchServerTimestamp() a couple of seconds after having connected or after having entered a room (make sure you have sent several reliable messages before doing so, so that the rtt gets more accurate) to re-fetch the server time. This usually gives a more accurate value than the automatic initial fetch that gets done shortly after establishing the connection.

    Please be aware that comparing the server time of two clients is only useful if both clients are in the same lobby or in the same game room, as otherwise they are not guaranteed to be connected to the same server (on Photon Cloud a game room is never hosted on the same server like a lobby room, as the former gets hosted on a game and the latter on a master server, two different game rooms are rather unlikely to be hosted on the same server, as there are a lot of game servers, two lobbies of the same appID and inside the same server region are currently very likely to be hosted on the same master server, but this is not guaranteed and may get a lot less likely in the future). In the scenario that two clients are on different servers the server time is fundamentally different for them and comparing it is pointless.