How to reconnect before connection timeout?
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on Photon Server.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
How to reconnect before connection timeout?
dcerny
2018-10-17 10:23:31
Hello, I experience this behavior of photon server plugin:
- I am an user in a room X (player TTL is 1sec, Room TTL 3mins)
- the client dies (without proper disconnect)
- I immediately try to reconnect and re-join to the same room with the same user (before connection timeout expires)
- re-join attempt fails. related log messages on server side:
WARN Photon.Hive.HiveGame -
JoinApplyGameStateChanges: Game 'Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705' userId 'sgl:gikx-syrk-n3in-nd65' failed to join. msg:Join failed: UserId 'sgl:gikx-syrk-n3in-nd65' already joined the specified game (JoinMode=3). -- peer:GameClientPeer: PID 15, IsConnected: True, IsDisposed: False, Last Activity: Operation 226 at UTC 10/16/2018 3:22:06 PM in Room Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705, IP 192.168.2.55:41673, - join attempt fails too
WARN Photon.Hive.HiveGame -
JoinApplyGameStateChanges: Game 'Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705' userId 'sgl:gikx-syrk-n3in-nd65' failed to join. msg:Join failed: UserId 'sgl:gikx-syrk-n3in-nd65' already joined the specified game (JoinMode=0). -- peer:GameClientPeer: PID 17, IsConnected: True, IsDisposed: False, Last Activity: Operation 226 at UTC 10/16/2018 3:22:07 PM in Room Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705, IP 192.168.2.55:40362,
If I wait for cca 1min, the client connection timeotes and I am able to join the same room with the same user. But I need to do this BEFORE the timeout. Any suggestion?
than you
Comments
hi, @dcerny
What auth mode are you using? you should use token auth. and during rejoining you should provide a token from the previous session. Otherwise, it will not allow you to rejoin
best,
Ilya
we use custom authentication. And we provide auth data during connection. The problem is not in establishing connection, but in rejoin/jion. The workflow is (PUN code):
- PhotonNetwork.AuthValues = new AuthenticationValues {...}
- PhotonNetwork.ConnectUsingSettings(version) - SUCCESS
- PhotonNetwork.CreateorJoinRoom(...) - SUCCESS
- kill client
- repeat steps 1+2 - SUCCESS
- PhotonNetwork.ReJoinRoom() - FAILURE
- PhotonNetwork.JoinRoom() - FAILURE
hi, @dcerny
you do not need to repeat 1) and 2) when you rejoin. That your main mistake. I'm not sure how to do this right on the client side. @JohnTube please help here.
best,
ilya
Hi @dcerny,
Thank you for choosing Photon!
Sorry about my late comment I was on vacation.
OK, I see the issue.
I think it's because the current Photon Server version does not support "sessions" if token changes, @chvetsov can confirm, clarify or rectify.
If the client disconnects unexpectedly, the server may keep an active connection for a peer in the room for a while, during this period it won't accept any new connection with the same UserId and different token.
What you could do to double check:
Try reconnect and rejoin (keeps the same token, connects to the game server directly): If you do not kill the client but instead force a client timeout disconnect (e.g. move the app to the background and then foreground again after client connection timeout 10 seconds without keep-alive/acks only background thread if applicable) and try ReconnectAndRejoin it should work with self-hosted server.
You could also try LeaveRoom(true) then Rejoin() once on master server.
Try same repro steps from your previous comment but on Photon Cloud.
Hi @JohnTube ,
I am facing the same problem, when our players get disconnected, they won't be able to rejoin too soon, I see the error
is there anyway to "force" a rejoin? I have tried LeaveRoom(true) before calling Rejoin and it does not seem to be working, (At that point i am not even connected to the game server, i don't think it's going to help the game server finding out i am already disconnected)
Thanks for your help
Ting
Hi @ltx,
You could cache (on device between 'app sessions') the room name, AuthenticationValues.Token
, the Game Server's IP address of the previous 'server/connection/auth session' and reuse it in the new 'server/connection/auth session' and perform a ReconnectAndRejoin
(this a PUN feature where you do a quick reconnect, shortcut to Game Server and rejoin the room) or cache the room name and AuthenticationValues.Token
to perform a Rejoin
.
I did not test this and it may require changes in client code to allow injecting AuthenticationValues.Token
and server address/type.
cesarnavie
2019-01-13 05:45:15
I'm having the exact same problem.
Sadly, @JohnTube 's post didn't help much, for one reason: AuthenticationValues.Token always returns empty. I thought that token would be synced automatically between the server and Unity, but nope it's always empty. And I have no idea how to even access that token in my Plugin code so that I could maybe even send the token itself through an event to the player.
hi, @cesarnavie
Your post contains two questions.
- is client side issue. Please ask in corresponding forum section. you will get more help
- in your plugin you do not get access to token. The only thing you have access is AuthCookie. AuthenticationCookie is part of token and can be set using Custom Authentication. Here you may find some description: https://doc.photonengine.com/en-us/server/v4/applications/loadbalancing/custom-authentication/#advanced_features. Look for AuthCookie
best,
ilya
@cesarnavie @ltx @dcerny
I've had the same problem recently and the solution in my case was to properly set MinimumTimeout and MaximumTimeout properties for loadbalancing in PhotonServer.config so that server realizes the client has disconnected much faster. Also I don't use any kind of custom athentication and I use udp protocol. Hope that helps )