Navigation

  • Recent
  • Tags
  • Users
  • Search
  • Login
Colyseus
  • Login
  • Search
  • Recent
  • Tags
  • Users

Documentation GitHub

We're migrating to GitHub Discussions. This forum does not accept new registrations since April 6, 2023.
  1. Home
  2. fieldmops
F

fieldmops

@fieldmops

Chat Follow Unfollow
0
Reputation
1
Posts
1.2k
Profile views
0
Followers
0
Following
Joined 16 Feb 2020, 15:20 Last Online 16 Feb 2020, 15:36

  • Profile
  • More
    • Continue chat with fieldmops
    • Flag Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups
fieldmops Follow

Posts made by fieldmops

Multiple Clients in the same Cocos application

Hello there! :)

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?

My implementation is as follows:

GameScene.cpp:

Client* client = new Client("ws://localhost:2567");
... //game code

initPlayers(){
auto player1 = Player(client, position, points, whatever);
}

Player.cpp:

Client* gameClient;
Room<State>* room;

Player(Client* client, Vec2 position, int points, whatever){
this->gameClient = client;
...
this->onConnectToServer();
}

onConnectToServer(){
...//defining options
client->joinOrCreate("lobby", options, [=](std::string err, Room<State>* _room){
...//basically the code from the example project
}
}

This does NOT work with more than one players. The first player connects, all the others don't. I just get "Error -1 in request" 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

Thanks for every help in advance!

posted in Questions & Help • 16 Feb 2020, 15:41

© 2023 Endel Dreyer