Best way to reconnect to Master Server after timeout?
Options
Hi I would like to know what the best way is to reconnect to the Master Server when the client times out.
Currently I start a coroutine at .OnDisconnected() that calls .Reconnect() every 2 seconds.
This seems to work because when I turn off my internet connection for like 10 seconds the coroutine gets called. When the internet connection is back the .Reconnect() successfully connects me to the Master Server again.
So this solution works, but my question is if this is the suggested solution? Do you guys also use coroutines to reconnect?
Thanks!
Using: Photon PUN 2.4
Currently I start a coroutine at .OnDisconnected() that calls .Reconnect() every 2 seconds.
This seems to work because when I turn off my internet connection for like 10 seconds the coroutine gets called. When the internet connection is back the .Reconnect() successfully connects me to the Master Server again.
So this solution works, but my question is if this is the suggested solution? Do you guys also use coroutines to reconnect?
Thanks!
Using: Photon PUN 2.4
1
Comments
-
I have the same issue. The main problem is that
PhotonNetwork.IsConnected
returnsTrue
even if the connection has timed out. It only starts returningFalse
once a networked action fails (e.g. trying to create a room). Is this intended behavior?1 -
@Burny123 I opted to solve if this way: I simply call this method in
Update()
:private void checkNetworkStatus() { if (initiallyConnected & !isConnecting && !PhotonNetwork.IsConnectedAndReady) { Debug.Log("Reconnecting..."); PhotonNetwork.Reconnect(); isConnecting = true; } }
And then don't forget to setisConnecting
in the successful connection callback toFalse
. It works because after a timeout,PhotonNetwork.IsConnectedAndReady
is onlyFalse
the first time it's called after that Photon realizes something's off and shows you the correct connection status.0 -
Hi @Burny123 @shafy @Maheshk_218,
As my colleague, @Christian_Simon pointed out hereReconnect
orReconnectAndRejoin
are not meant to be called repeatedly. Instead, here is the expected workflow:
1- detect unexpected disconnection
2- recover from unexpected disconnection
1 is usually a PUN callback indicating that the client has disconnected with the cause/reason. The callback could be delayed in some case(s) and you may want to implement your own way of detecting disconnects earlier if you really need to.
2 is just a matter of callingReconnect
andReconnectAndRejoin
once.0