Reconnect after application is terminated (on mobile too)
Options
I'm trying to implement reconnection feature and I'm facing some problems when testing a case when the user force quits the application.
I can use ReconnectAndRejoin() or first Reconnect(), then ReJoinRoom() to reconnect to the room if the user disconnects from photon but still has application runnin.
However, if the the application gets terminated somehow (by user, or by operating system in order to free some memory), I can't reconnect to the room after the application starts.
Afeter restart client successfully connects to cloud server, then to lobby. But when I try to ReJoin room, I get an error
I noticed that in both cases(with and without terminating an app) PlayerID after disconnecting is -1, but it seems that in first case it is cached somewhere so that player can reconnect later.
Is reconnecting after application termination even possible? What is the correct way?
I can use ReconnectAndRejoin() or first Reconnect(), then ReJoinRoom() to reconnect to the room if the user disconnects from photon but still has application runnin.
However, if the the application gets terminated somehow (by user, or by operating system in order to free some memory), I can't reconnect to the room after the application starts.
Afeter restart client successfully connects to cloud server, then to lobby. But when I try to ReJoin room, I get an error
Operation failed: OperationResponse 226: ReturnCode: 32748 (User does not exist in this game). Parameters: {} Server: GameServer
I noticed that in both cases(with and without terminating an app) PlayerID after disconnecting is -1, but it seems that in first case it is cached somewhere so that player can reconnect later.
Is reconnecting after application termination even possible? What is the correct way?
0
Comments
-
Hi @DuckOfDoom,
Thank you for choosing Photon!
The error you are encountering is due to the room not properly configured during creation.
You need to allow:
- Player to rejoin after disconnecting. UseRoomOptions.PlayerTTL
to specify how long the player can be inactive (disconnected) inside the room's ActorsList.
- (optionally) Room to stay in Photon server memory for few minutes (max for Cloud is 5) after all players left. UseRoomOptions.EmptyRoomTTL
to set this behaviour.0 -
Thanks for the fast answer.JohnTube said:
- Player to rejoin after disconnecting. UseRoomOptions.PlayerTTL
to specify how long the player can be inactive (disconnected) inside the room's ActorsList.
I already have PlayerTTL and EmptyRoomTTL set to a reasonable values and I tried increasing them, so this might no really be a problem. And players can easily reconnect after disconnecting if they don't terminate the application.
Maybe the problem is that I ha a playerID of -1?0 -
Maybe the problem is that I ha a playerID of -1?I think that is normal if player is not joined to a room.
By "terminated" you mean app closed and you open it again right?
What TTL values are you using?
Are you using a unique UserID per player? That should be the case since you mentioned player can rejoin after disconnection, just double checking.
I still think that the player is trying to rejoin after PlayerTTL expired.
In PUN 1.81, we added a callbackOnPhotonPlayerActivityChanged(PhotonPlayer otherPlayer)
to know if when a player has left for good or if he left and may come back. You may want to implement this callback and check when a player has left for good which means a PlayerTTL expired or player intentionally left for good (calledLeaveRoom(false)
).
Or if you rejoin the room by name, which is what should happen if the app has been terminated, another explanation is possible: while the player is disconnected, room was closed and recreated (a new room is created with same name) so it does not contain the player.
How are you caching the list of rooms the player belongs to (can rejoin)?
A solution is to callJoin
instead ofRejoin
when this error is thrown in case you do not care about keeping same actorNr (playerID).0 -
Right now I'm just turning play mode off in unity editor and then starting it again in order to simulate app termination.
I'm testing this flow with a hardcoded room name for both players. In production environment we will have a custom server that saves room name for the player to rejoin.
I've used TTL values of 5 minutes.
Also, I have a game with two players and another player is still in game and can play as usual, while other disconnects, howeverPhotonNetwork.room.PlayerCount
returns 2 even when the other player has disconnceted. I guess this is normal because PlayerTTL did not expire yet.
I'll try to log that callback output and see what I can find, thanks.0 -
Well,
OnPhotonPlayerActivityChanged(PhotonPlayer otherPlayer)
returns me the player, whose IsInactive property is "true". Which is correct I guess, because player's application got terminated.
No other way to do this? I see people asking similar questions (http://forum.photonengine.com/discussion/9575/how-can-i-allow-a-disconnected-player-and-only-him-to-connect-back-in-the-game#latest) , this must be the common case for mobile games.0 -
My guess is that UserID changes after app termination (please log them and compare). Please make sure to use same UserID across app sessions. I also posted on the other discussion.1
-
Please make sure to use same UserID across app sessions.
Looks like this was the problem, thanks a lot! I should have read the documentation more thoroughly.
Thanks for your support!0