Examples of ReconnectAndRejoin
I was wondering if there was an sample projects or examples of how to properly setup ReconnectAndRejoin? We are hosting our own Photon Server and I cannot seem to reconnect and rejoin the room. Everytime I reestablish a connection, I see the following error in our server logs:
I have tried many variations of the PlayerTtl and nothing seems to work. I would love to see some examples of how this is supposed to be implemented.
Best,
Adam
2017-09-14 15:23:33,736 [28] WARN Photon.Hive.HiveGame - JoinApplyGameStateChanges: Game '7d108d42-6492-4129-9994-ff2563c5f259' userId '18b1f8d1-fc3e-4cb5-8b72-52336f0b3616' failed to join. msg:Join failed: UserId '18b1f8d1-fc3e-4cb5-8b72-52336f0b3616' already joined the specified game (JoinMode=3). -- peer:GameClientPeer: PID 185, IsConnected: True, IsDisposed: False, Last Activity: Operation 226 at UTC 9/14/17 8:23:33 PM in Room 7d108d42-6492-4129-9994-ff2563c5f259, IP 10.211.55.2:54526,
I have tried many variations of the PlayerTtl and nothing seems to work. I would love to see some examples of how this is supposed to be implemented.
Best,
Adam
0
Comments
-
Hi @mr_bulldops,
I think the error can happen due to one or two reasons:
1. You are callingReconnectAndRejoin
"too quickly" after a client disconnection that the server is still not aware of: the server may still keep the same peer connection (same UserId) and the actor is still marked "active".
2. Another peer with same UserId is connected to the room from another client/device/connection.
ReconnectAndRejoin is best used after timeout disconnection or on mobile devices. (see below)
So it is not related to the PlayerTTL.
I will move this to the Photon Server category.
Adam you can send us an email if this issue persists. We may have something to "ForceRejoin".
Also, the "new" rejoin is now based on UserIDs instead of ActorNr, this is achieved usingRoomOptions.CheckUserOnJoin
, you can revert to the old rejoin but it's not recommended.
---
More info:
PlayerTTL vs. EmptyRoomTTL- PlayerTTL: how long an actor can stay inactive inside the room.
- EmptyRoomTTL: how long a room with no active actors should stay alive on Photon Servers memory.
- Active actor: a player connected and joined to a room.
- Inactive actor: a player who joined the room but left temporarily and its spot (actor entry with all the info) is left inside the actors list but marked as inactive.
PUN'sPhotonNetwork.ReconnectAndRejoin()
:
In order for ReconnectAndRejoin to properly work the room should still exist on the same GameServer and the player can rejoin (is still inside the room as inactive actor).
I'm assuming the customer is targeting mobile platforms.
PUN has a background thread that keeps sending ACKs to the server to maintain the client connection and in this particular case joined to the room.
This background thread has a timeout also, after which client disconnects gracefully from the server thus leaves the room.
The background thread does not work on iOS.
The default background thread timeout is 60 seconds. CheckPhotonNetwork.BackgroundTimeout
>.
So here are different scenarios to consider if the player's app goes to background while joined to a room:
1. was the player alone inside the room?
1.a. if yes then the empty room's destruction timer (value is EmptyRoomTTL) will start as soon as the player leaves/disconnects. Unless someone joins meanwhile.
1.b. if no, then the other players will keep the room alive as long as they are joined/connected.
2. mobile platform:
2.a. if iOS then the player will be disconnected as soon the app moves to the background.
2.b. if not iOS then the player will stay joined to the room until background thread timer expires (default is 60 seconds).
So we can safely assume thatReconnectAndRejoin
can be called after x milliseconds where x is:if iOS: x < min(EmptyRoomTTL, y*)
if not iOS: x < BackgroundTimeout + min(EmptyRoomTTL, y*)
*y:
if PlayerTTL >= 0
y = PlayerTTL
else
y = int max0 - PlayerTTL: how long an actor can stay inactive inside the room.
-
0
-
i've removed my answer because they were not correct
please report what version of Sdk are you using?
are you using token auth?
best,
ilya0 -
Sorry, didn't get any email notifications of a response. I'll review this information more thoroughly shortly.
Photon Server SDK: 4-0-29-11263
Thanks0 -
So, I've tried setting both the PlayerTTL and BackgroundTimeout to low values (1s). I wait well over that and still can't seem to reconnect and rejoin. I've tried both ReconnectAndRejoin as well as Reconnect followed by Rejoin. Both result in the same error which I posted above. When I try the two separate calls, I am able to successfully reconnect to photon, but RejoinRoom fails. Are these not the correct calls or order of calls to rejoin a game? Could this possibly be something in our Photon Server code or configuration causing it to fail?
Thanks0 -
@mr_bulldops you may debug your server code to see what is going on. There is method ActorManager.VerifyCanJoin. you may set break point there and see why connection is rejected
best,
ilya0 -
Hi @mr_bulldops,
If you wait until PlayerTTL is expired then you should get a different error: JoinFailedWithRejoinerNotFound (32748).0