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! Your search result can be found below. Plus, we offer support via these channels:

Try Our

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

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.

Reconnect after application is terminated (on mobile too)

2017-04-05 11:24:21

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

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?


2017-04-06 09:18:44

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. Use RoomOptions.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. Use RoomOptions.EmptyRoomTTL to set this behaviour.

2017-04-06 09:29:07

@JohnTube wrote:

  • Player to rejoin after disconnecting. Use RoomOptions.PlayerTTL to specify how long the player can be inactive (disconnected) inside the room's ActorsList.

Thanks for the fast answer.

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?

2017-04-06 13:23:54

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 callback OnPhotonPlayerActivityChanged(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 (called LeaveRoom(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 call Join instead of Rejoin when this error is thrown in case you do not care about keeping same actorNr (playerID).

2017-04-06 13:32:22

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, however 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.

2017-04-12 08:22:15

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 ( , this must be the common case for mobile games.

2017-04-12 10:09:26

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.

2017-04-12 13:07:38

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!

Back to top