Best way to reconnect to Master Server after timeout?

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?


Using: Photon PUN 2.4


  • I have the same issue. The main problem is that PhotonNetwork.IsConnected returns True even if the connection has timed out. It only starts returning False once a networked action fails (e.g. trying to create a room). Is this intended behavior?
  • shafyshafy
    edited December 2018
    @Burny123 I opted to solve if this way: I simply call this method in Update():
    private void checkNetworkStatus() {
        if (initiallyConnected & !isConnecting && !PhotonNetwork.IsConnectedAndReady) {
            isConnecting = true;
    And then don't forget to set isConnecting in the successful connection callback to False. It works because after a timeout, PhotonNetwork.IsConnectedAndReady is only False the first time it's called after that Photon realizes something's off and shows you the correct connection status.
  • JohnTubeJohnTube mod
    edited December 2018
    Hi @Burny123 @shafy @Maheshk_218,

    As my colleague, @Christian_Simon pointed out here Reconnect or ReconnectAndRejoin 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 calling Reconnect and ReconnectAndRejoin once.
Sign In or Register to comment.