Introducing a simple webserver for multiplayer games

Introducing a simple nodejs, websocket based webserver for multiplayer games:

It handles and tracks rooms names for different sessions.

Emit ‘create or join’ event with room name as a parameter on the both sides. It will allow you to send in game messages only to participants in the room.

1 Like

Hi,

It looks neatly implemented though it’s all in a single index.js, right?

My two cents:

  • Websocket is TCP based, so it’s not suitable for real-time games. WebRTC is more powerful and uses faster UDP.
  • Colyseus is a splendid framework that works very well with Phaser. Check out this tutorial to have a feel of what it does.

Colyseus also has a cloud service to handle rooms & more. Definitely worth checking!

Yes, its quit simple, I’ve designed it for my own projects and have thought that it may be useful for someone else.

In my mind for developing its better to use something simple and lightweight, you could jump to something bigger any time you will understand you really need that.

And Phaser is frontend tool, it doesn’t mind what you will use on the server side.

1 Like

Agreed with starting lightweight, same here. I’m however facing some tricky items now that I’m to handle starting cloud instances on demand. Different topic.

I use Phaser on the backend side too, actually, as a monorepo. Common logic is shared among front-end and backend-end specific sub-projects.

The following article helped me getting Phaser to run in headless mode. Works wonders.

It’s the only way I found to have an all-in-one solution offering:

  • pure client gameplay
  • P2P play (think oldschool multiplayer with a “host” that’s both player and server)
  • dedicated server

Scenario: I’m a client, connected to a server (or P2P host), I loose the connection. I need to handle logic myself seamlessly.
It’s possible when server and client share the exact same logic without need to rewrite similar bits of logic between tiers.

though phaser can run on the server I wouldn’t recommend that at all, is too much stuff you don’t need on the server, you can consume tons less resources by just running a physics engine if it’s applicable to your game, otherwise even tile or positional movement would be so much better, at the end it all depends on what your game requires

Agreed regarding resource usage, but I’d rather pay 200% hosting costs than spend 3-5x more time doing patchwork to keep “blind” physics in sync with sprites/tiles/physicsEditor shapes.

This is of course a very personal opinion :slight_smile:
I might just have it all wrong if my physics are so tightly bound to the sprites / tiles they represent.

Oh but I remember browsing your code, Reldens right? Your Wizard logo reminds of that.
Good stuff you have there.

Yup, Reldens is my project, there I have Colyseus + P2JS (as physics engine) on the server side + Phaser on the client, though I’m now restructuring the code to use drivers for everything, so I can easly replace any of those, like P2JS for MatterJS, or Phaser for Pixi, etc.

I’m however facing some tricky items now that I’m to handle starting cloud instances on demand. Different topic.

Could you expand on this topic? I’ve been working on an on demand hosting solution for games (https://hathora.dev/) which I’d be curious to learn whether it could be useful to you.

websocket is perfectly fine for real time games. Couple it with client prediction and entity interpolation and it works great.