<?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[Multiple Clients in the same Cocos application]]></title><description><![CDATA[<p>Hello there! :)</p>
<p>I started using Colyseus a few weeks ago and so far everything is running smoothly. I am writing a game with a local and an online multiplayer. For local multiplayer I wanted to start a local Colyseus server and connect several clients to it. I wrote a test in javascript and everything worked fine, but I wrote the game in Cocos2D and I am stuck with the client implementation. As long as I am only connecting one client with one room, it works. But as soon as I want to open multiple rooms with the same client, only one room connects and all the others fail to connect. I've also written a test with multiple clients, each with one room. That seems to work, but my understanding of Colyseus is, that I just need to create one client. Is this wrong and I actually need to create multiple clients, one for every room, or is my implementation wrong?</p>
<p>My implementation is as follows:</p>
<p>GameScene.cpp:</p>
<p>Client* client = new Client(&quot;ws://localhost:2567&quot;);<br />
... //game code</p>
<p>initPlayers(){<br />
auto player1 = Player(client, position, points, whatever);<br />
}</p>
<p>Player.cpp:</p>
<p>Client* gameClient;<br />
Room&lt;State&gt;* room;</p>
<p>Player(Client* client, Vec2 position, int points, whatever){<br />
this-&gt;gameClient = client;<br />
...<br />
this-&gt;onConnectToServer();<br />
}</p>
<p>onConnectToServer(){<br />
...//defining options<br />
client-&gt;joinOrCreate(&quot;lobby&quot;, options, [=](std::string err, Room&lt;State&gt;* _room){<br />
...//basically the code from the example project<br />
}<br />
}</p>
<p>This does NOT work with more than one players. The first player connects, all the others don't. I just get &quot;Error -1 in request&quot; for every connection other than the first one. Now, if I just create a new Client in every Player object it works fine. Is this the way to do it, or is that a bad hacky way that just works? :D</p>
<p>Thanks for every help in advance!</p>
]]></description><link>http://discuss.colyseus.io/topic/321/multiple-clients-in-the-same-cocos-application</link><generator>RSS for Node</generator><lastBuildDate>Sat, 14 Mar 2026 13:48:50 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/321.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Feb 2020 15:41:00 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Multiple Clients in the same Cocos application on Invalid Date]]></title><description><![CDATA[<p>Hello there! :)</p>
<p>I started using Colyseus a few weeks ago and so far everything is running smoothly. I am writing a game with a local and an online multiplayer. For local multiplayer I wanted to start a local Colyseus server and connect several clients to it. I wrote a test in javascript and everything worked fine, but I wrote the game in Cocos2D and I am stuck with the client implementation. As long as I am only connecting one client with one room, it works. But as soon as I want to open multiple rooms with the same client, only one room connects and all the others fail to connect. I've also written a test with multiple clients, each with one room. That seems to work, but my understanding of Colyseus is, that I just need to create one client. Is this wrong and I actually need to create multiple clients, one for every room, or is my implementation wrong?</p>
<p>My implementation is as follows:</p>
<p>GameScene.cpp:</p>
<p>Client* client = new Client(&quot;ws://localhost:2567&quot;);<br />
... //game code</p>
<p>initPlayers(){<br />
auto player1 = Player(client, position, points, whatever);<br />
}</p>
<p>Player.cpp:</p>
<p>Client* gameClient;<br />
Room&lt;State&gt;* room;</p>
<p>Player(Client* client, Vec2 position, int points, whatever){<br />
this-&gt;gameClient = client;<br />
...<br />
this-&gt;onConnectToServer();<br />
}</p>
<p>onConnectToServer(){<br />
...//defining options<br />
client-&gt;joinOrCreate(&quot;lobby&quot;, options, [=](std::string err, Room&lt;State&gt;* _room){<br />
...//basically the code from the example project<br />
}<br />
}</p>
<p>This does NOT work with more than one players. The first player connects, all the others don't. I just get &quot;Error -1 in request&quot; for every connection other than the first one. Now, if I just create a new Client in every Player object it works fine. Is this the way to do it, or is that a bad hacky way that just works? :D</p>
<p>Thanks for every help in advance!</p>
]]></description><link>http://discuss.colyseus.io/post/1063</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1063</guid><dc:creator><![CDATA[fieldmops]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>