The best way to immediately reconnect after a disconnect

Options
Hi everyone!

Photon obviously doesn't give us a nice way to immediately know if internet connection to our game has been lost. Check out next 3 comments from this post if you need proof.

As suggested there, I've written a corutine that in short intervals sends a request to my own server. If we stop receiving a responce from the server than the game can immediately know there is no internet connection and react accordingly. Next, as soon as we again start receiving responces from the server, the game immediately knows the internet is reachable and it's time to call PhotonNetwork.ReconnectAndRejoin()

And here I get this error: ReconnectAndRejoin() failed. Can only connect while in state 'Disconnected'. Current state: Connected

The reason for this is that I reconnected so fast (just in 8 seconds after a disconnect) that Photon still thinks that we are connected (cause disconnectTimeout is 10 sec).

My question: can I force PhotonNetwoork.networkingPeer.State to be Disconnected so that I could call reconnect accordingly?

Thank you!

Comments