GitHub | Documentation | Become a Patron

Bug on Unity Colyseus after reconnect client



  • After reconnect client, if there is any state changes, the unity client room listener won't pick up any update on room state.
    The reconnected client can send signal to server, but server update on roomstate, or broadcast, or send message to client all failed. The client stop receive any feedback. Anyone can help me?


  • administrators

    Hi @Soh-Sea-Kiat, by reconnection you mean calling ReJoin? Cheers



  • @endel Yup, after Rejoin,

    anything in try block still can pass back to client, but when client send message to the room, or any update on roomstate, client won't listen any changes anymore, seems to me server is not casting data back to reconnected client

    code block

    async onLeave (client, options) {

        console.log(client.id+ " Leaving...");
        
        // inactivateclient
        this.state.deactivateClient(client);
        this.broadcast({isDeactivated: client.id});
    
        try {
            // allow disconnected client to rejoin into this room until 20 seconds
            await this.allowReconnection(client, 300);
    
            // client returned! let's re-activate it.
            console.log(client.id + " reconnect back !");
            this.state.activateClient(client);
          
            // push updated roominfo to reconnect client
            this.broadcast({isActivated: client.id});
            
        } catch (e) {
    
            // 20 seconds expired. let's remove the client.
            this.state.removePlayer(client);
        }
    } 
    

    onMessage (client, data) {

                if(data.isInit != undefined){
                    this.state.changePlayerReady(client, data.color, data.isReady);
                    this.broadcast({test: "message"});
                }
    

    }


  • administrators

    Hi @soh-sea-kiat, I see. It must be something on the client-side. Are you possibly forgetting to create a new coroutine for the ReJoin()?

    Like here:

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

    Cheers



  • Hi @endel I already used client.Rejoin() to get reconnect back from client side, and I can successfully reconnect back to server with a new coroutine, just that after the reconnection, I couldn't recieve any update from server side but still can room.send() data to the server.