Can't get basic client/server communication to work


I've been trying to get Colyseus up and running but I can't manage to do it. I made it connect a few times but not anymore.

I'm getting almost always the same error:

join error MatchMakeError: "game_room" not defined
    at new MatchMakeError (/home/squ3ck/projects/test/client/node_modules/colyseus.js/lib/Client.js:58:28)
    at Client.<anonymous> (/home/squ3ck/projects/test/client/node_modules/colyseus.js/lib/Client.js:182:35)
    at step (/home/squ3ck/projects/test/client/node_modules/colyseus.js/lib/Client.js:45:23)
    at (/home/squ3ck/projects/test/client/node_modules/colyseus.js/lib/Client.js:26:53)
    at fulfilled (/home/squ3ck/projects/test/client/node_modules/colyseus.js/lib/Client.js:17:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  code: 4210

I removed most of my code and left with barebone example code:

GameRoom.ts is from the example code at:


import http from "http";
import express from "express";
import cors from "cors";
import { matchMaker, Server } from "colyseus";
import { monitor } from "@colyseus/monitor";

import { GameRoom } from "./GameRoom";

const port = Number(process.env.PORT || 2567);
const app = express()


const gameServer = new Server({
  server: http.createServer(app),
  express: app,
  pingInterval: 0,

// register your room handlers
// gameServer.define("my_room", MyRoom);
gameServer.define("game_room", GameRoom);

app.use("/colyseus", monitor());

console.log(`Listening on ws://localhost:${ port }`)


var colyseus = require('colyseus.js')

let client = new colyseus.Client("ws://localhost:2567");

client.joinOrCreate("game_room", {}).then(room => {
  console.log("joined successfully", room);
}).catch(e => {
  console.error("join error", e);

Creating the room from the server works, but still can't join from the client.

matchMaker.createRoom("game_room", {}).then(room => console.log(room));

prints this:

RoomCache {
  clients: 0,
  locked: false,
  private: false,
  maxClients: Infinity,
  createdAt: 2020-03-28T00:05:33.941Z,
  name: 'game_room',
  processId: 'hmecnUvQa',
  '$rooms': [ [Circular] ],
  roomId: 's2BR8Qfx3'

I have installed the server with npm init colyseus-app and the client with npm install --save colyseus.js

It has also happened that the client your report a successful room join but no join events would fire on the server.

What am I missing? Thanks!

hi,you should use matchMaker.defineRoomType to defind this room.

Thanks for your reply!

I think this was a networking issue in the end (maybe due to WSL on Windows) -- I changed the server port and now everything's working even without