Can't rejoin room in Unity3D

Hi, I am struggling to rejoin my client with server. I am using room.rejoin(roomName, sessionID) on my connection close event. But it is not sending request back to server. While we have also used allowReconnection on server side

Hi @usamasermad, which version of Colyseus are you using? From version 0.9.27 to 0.9.29 the reconnection feature was broken. I highly recommend getting the latest one.

How does your allowReconnection looks like? It would be helpful if you provide some code for us to have a look at.


@endel we are using 0.9.32 on server side.

  • Here is the snippet of the server side code

  • Here is the snippet of the unity 3d


Hey @usamasermad, I believe you should call StartCoroutine(room.Conect()) after calling ReJoin, like here:

Let me know if that works for you, cheers!

So you mean that in my Rejoin coroutine i just need to add

room.OnReadyToConnect += (sender, e) => 
    Debug.Log("Ready to connect to room!");
     StartCoroutine (room.Connect ());

or only StartCoroutine (room.Connect ()); and everything else till Rejoin remains the same

@usamasermad yes, like this:

room = client.ReJoin(roomName, sessionId);
room.OnReadyToConnect += (sender, e) => 
    Debug.Log("Ready to connect to room!");
     StartCoroutine (room.Connect ());

As you suggested I changed my code to this but didn't reconnected
0_1551707666373_new rejoin.PNG

and these are my logs for your convenience
0_1551707699468_rejoin logs.PNG

@usamasermad I see, do you possibly have onAuth() validation the server-side? If you do, I'd ask you to try a bit differently:

Dictionary<string, object> options = new Dictionary<string, object> ();
options.Add ("sessionId", sessionId);
options.Add(/* your authentication options */)

room = client.Join(roomName, options);
room.OnReadyToConnect += (sender, e) => 
    Debug.Log("Ready to connect to room!");
     StartCoroutine (room.Connect ());

Currently we don't have any kind of validation required for this room. It is just only named as onAuth() because we send email and password to the server in this room but that is only after clicking on register button which means we dont have to send anything automatically to the server

@usamasermad I've just tested this and apparently it works fine. Can you check the demo project on the official colyseus-unity3d repository?

I've organized a bit better the demo project and added a "Re-Join Room" button to demonstrate. The only thing I've changed in the Colyseus Client itself was the ability to call room.Leave(false) to force an "unconsented" leave in the server-side. (see release notes)

Hope this helps, let me know if you still can't perform a reconnect.

@endel Thanks a lot for your quick solution. Rejoin works like a charm for me now. New updated demo project is also very good organized and easy to understand and has cleared a lot of confusions.

@endel Hey sorry to interrupt but I have noticed that unity client cant reconnect if our connection is closed i.e client.OnClose. However Rejoin works fine if client is not closed

  • Like in this

Should i create new client and then try to Rejoin it with server or it is not yet implemented on serverside?

For your knowledge I am testing it by increasing my packet drop rate to 90%. It works fine if i leave the room with consented = false. But doesn't reconnect if client connection is closed

@usamasermad yes, you should ensure the Client connection is open before performing a ReJoin. If you're going to instantiate a new Client, make sure it has the same as the one who initiated the first connection to the room (