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
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!
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!
0
Comments
-
Well, as a temporary solution I'm just calling
PhotonNetwork.Disconnect()
forcing networkingPeer.State to be disconnected. I'm not sure if it's correct because explicit disconnect should clear room event cache which I need for my game. But since the internet is absent at the time of the call, it works.
Would be nice to hear your opinion on this guys!0 -
Hi @1_Mad_Developer,
What PUN version are you using?
In my opinion, your solution is OK if you're sure there is no Internet.
N.B.
On a side note, you should also be able to detect connection behind "captive portal" and not only disconnection. You could do this by sending an HTTP GET request and expecting 204 to one of the following addresses:- http://clients3.google.com/generate_204
- http://google.com/generate_204
- http://connectivitycheck.gstatic.com/generate_204
- http://www.gstatic.com/generate_204
1 - http://clients3.google.com/generate_204
-
Thanks for the responce!
I'm using PUN v1.76 (21 Sept 2016)On a side note, you should also be able to detect connection behind "captive portal" and not only disconnection. You could do this by sending an HTTP GET request and expecting 204 to one of the following addresses:
http://clients3.google.com/generate_204
http://google.com/generate_204
http://connectivitycheck.gstatic.com/generate_204
http://www.gstatic.com/generate_204
or send to http://www.google.com/blank.html and expect an empty 200 response.
I will look into that Thanks!0