How to reconnect before connection timeout?

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

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).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

How to reconnect before connection timeout?

dcerny
2018-10-17 10:23:31

Hello, I experience this behavior of photon server plugin:

  1. I am an user in a room X (player TTL is 1sec, Room TTL 3mins)
  2. the client dies (without proper disconnect)
  3. I immediately try to reconnect and re-join to the same room with the same user (before connection timeout expires)
  4. 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,
  5. 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

chvetsov
2018-10-18 06:42:27

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

dcerny
2018-10-18 08:28:00

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):

  1. PhotonNetwork.AuthValues = new AuthenticationValues {...}
  2. PhotonNetwork.ConnectUsingSettings(version) - SUCCESS
  3. PhotonNetwork.CreateorJoinRoom(...) - SUCCESS
  4. kill client
  5. repeat steps 1+2 - SUCCESS
  6. PhotonNetwork.ReJoinRoom() - FAILURE
  7. PhotonNetwork.JoinRoom() - FAILURE

chvetsov
2018-10-19 15:24:08

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

JohnTube
2018-10-29 11:20:47

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:

  1. 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.

  2. You could also try LeaveRoom(true) then Rejoin() once on master server.

  3. Try same repro steps from your previous comment but on Photon Cloud.

ltx
2018-11-29 11:39:54

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

2018-11-29 19:25:03,603 [12] WARN Photon.Hive.HiveGame - JoinApplyGameStateChanges: Game '868787ae-07a0-425b-bf04-a4bb4a4ff5c9' userId '8' failed to join. msg:Join failed: UserId '8' already joined the specified game (JoinMode=3). -- peer:GameClientPeer: PID 14, IsConnected: True, IsDisposed: False, Last Activity: Operation 226 at UTC 11/29/2018 11:25:03 AM in Room 868787ae-07a0-425b-bf04-a4bb4a4ff5c9, IP 192.168.1.15:37781,

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

JohnTube
2018-11-29 12:05:53

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.

chvetsov
2019-01-14 08:58:02

hi, @cesarnavie

Your post contains two questions.

  1. is client side issue. Please ask in corresponding forum section. you will get more help
  2. 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

Djebedia
2019-02-22 13:49:44

@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 )

Back to top