<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Java Colyseus Client problem with reconnect]]></title><description><![CDATA[<p>Hi all, please help. I have turn based server. There is problem with implement reconnect feature (after network disconnected) with saving user sessionId and roomId</p>
<p>The client:</p>
<pre><code>private val serverRoomListener = object : Room.Listener() {

    override fun onLeave() {
        Timber.e(&quot;leave&quot;)
        task = object : Timer.Task() {
            override fun run() {
                ServerClient.getInstance(ServerClient.Builder(url = SERVER_WS)).also {
                    it.setListener(object: Client.Listener{
                        override fun onMessage(message: Any?) {

                        }

                        override fun onClose(code: Int, reason: String?, remote: Boolean) {

                        }

                        override fun onError(e: java.lang.Exception?) {

                        }

                        override fun onOpen(id: String?) {
                            val rejoin = it.rejoin(currentRoom.name, it.id)
                            if(rejoin.hasJoined()){
                                task.cancel()
                            }
                        }

                    })
                    it.connect()

                }
            }
        }
          Timer.schedule(task, 10f, 0f, 0)
    }
</code></pre>
<p>Timer tick delay 10s</p>
<p>The server  &quot;colyseus&quot;: &quot;^0.9.32&quot;:</p>
<pre><code>onJoin(client, options?, auth?) {
    console.log(this.getLogTag(), options, auth, client.id);
    if (options.create) {
        this.state.masterPlayer = client.id
    } else {
        this.state.slavePlayer = client.id
    }
    console.log(this.getLogTag(), 'Client joined: ' + client.id);
    if (this.clients.length == 2) {
        this.lock();
        this.state.state = State.GAME;
        let command = {};
        this.clients.forEach(function (value) {
            command[value.id] = {}
        });
        this.state.command = command
    }
    this.broadcastPatch()
}

    async onLeave(client, consented?) {
        try {
            if (consented) {
                throw new Error(&quot;consented leave&quot;);
            }

            console.log(this.getLogTag(), &quot;Count users:&quot;, this.clients.length, consented);
            await this.allowReconnection(client);
            console.log(this.getLogTag(), 'Reconnect client: ' + client.id);
        } catch (e) {
            console.log(this.getLogTag(), 'Error: ' + e);
            console.log(this.getLogTag(), 'Client left: ' + client.id);

            if (client.id == this.state.masterPlayer) {
                this.state.masterPlayer = null;
             //   this.unlock()

            } else if (client.id == this.state.slavePlayer) {
                this.state.slavePlayer = null;
         //       this.unlock()
            }
        }
    }
</code></pre>
<p>reconnection server log <a href="http://prntscr.com/mvsyas" rel="nofollow">http://prntscr.com/mvsyas</a></p>
<p>Thanks for help.</p>
]]></description><link>http://discuss.colyseus.io/topic/221/java-colyseus-client-problem-with-reconnect</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 14:53:21 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/221.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 10 Mar 2019 08:29:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Java Colyseus Client problem with reconnect on Sun, 10 Mar 2019 22:23:04 GMT]]></title><description><![CDATA[<p>Hi all, please help. I have turn based server. There is problem with implement reconnect feature (after network disconnected) with saving user sessionId and roomId</p>
<p>The client:</p>
<pre><code>private val serverRoomListener = object : Room.Listener() {

    override fun onLeave() {
        Timber.e(&quot;leave&quot;)
        task = object : Timer.Task() {
            override fun run() {
                ServerClient.getInstance(ServerClient.Builder(url = SERVER_WS)).also {
                    it.setListener(object: Client.Listener{
                        override fun onMessage(message: Any?) {

                        }

                        override fun onClose(code: Int, reason: String?, remote: Boolean) {

                        }

                        override fun onError(e: java.lang.Exception?) {

                        }

                        override fun onOpen(id: String?) {
                            val rejoin = it.rejoin(currentRoom.name, it.id)
                            if(rejoin.hasJoined()){
                                task.cancel()
                            }
                        }

                    })
                    it.connect()

                }
            }
        }
          Timer.schedule(task, 10f, 0f, 0)
    }
</code></pre>
<p>Timer tick delay 10s</p>
<p>The server  &quot;colyseus&quot;: &quot;^0.9.32&quot;:</p>
<pre><code>onJoin(client, options?, auth?) {
    console.log(this.getLogTag(), options, auth, client.id);
    if (options.create) {
        this.state.masterPlayer = client.id
    } else {
        this.state.slavePlayer = client.id
    }
    console.log(this.getLogTag(), 'Client joined: ' + client.id);
    if (this.clients.length == 2) {
        this.lock();
        this.state.state = State.GAME;
        let command = {};
        this.clients.forEach(function (value) {
            command[value.id] = {}
        });
        this.state.command = command
    }
    this.broadcastPatch()
}

    async onLeave(client, consented?) {
        try {
            if (consented) {
                throw new Error(&quot;consented leave&quot;);
            }

            console.log(this.getLogTag(), &quot;Count users:&quot;, this.clients.length, consented);
            await this.allowReconnection(client);
            console.log(this.getLogTag(), 'Reconnect client: ' + client.id);
        } catch (e) {
            console.log(this.getLogTag(), 'Error: ' + e);
            console.log(this.getLogTag(), 'Client left: ' + client.id);

            if (client.id == this.state.masterPlayer) {
                this.state.masterPlayer = null;
             //   this.unlock()

            } else if (client.id == this.state.slavePlayer) {
                this.state.slavePlayer = null;
         //       this.unlock()
            }
        }
    }
</code></pre>
<p>reconnection server log <a href="http://prntscr.com/mvsyas" rel="nofollow">http://prntscr.com/mvsyas</a></p>
<p>Thanks for help.</p>
]]></description><link>http://discuss.colyseus.io/post/740</link><guid isPermaLink="true">http://discuss.colyseus.io/post/740</guid><dc:creator><![CDATA[daimonkor]]></dc:creator><pubDate>Sun, 10 Mar 2019 22:23:04 GMT</pubDate></item><item><title><![CDATA[Reply to Java Colyseus Client problem with reconnect on Invalid Date]]></title><description><![CDATA[<p>I have some new ideas <a href="https://github.com/colyseus/colyseus/issues/224" rel="nofollow">https://github.com/colyseus/colyseus/issues/224</a></p>
]]></description><link>http://discuss.colyseus.io/post/742</link><guid isPermaLink="true">http://discuss.colyseus.io/post/742</guid><dc:creator><![CDATA[daimonkor]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Java Colyseus Client problem with reconnect on Invalid Date]]></title><description><![CDATA[<p>Hello <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/367">@daimonkor</a> I'm using also Colyseus Client on Android, this unofficial portage to Java: <a href="https://github.com/doorbash/colyseus-java" rel="nofollow">https://github.com/doorbash/colyseus-java</a></p>
<p>I've seen you are using Kotlin, did you make your own version from doorbash's library?  I'm interested in your Kotlin lib :)</p>
<p>Thanks</p>
]]></description><link>http://discuss.colyseus.io/post/1264</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1264</guid><dc:creator><![CDATA[Meabo]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>