Need Help With An Authoritative WebSocket Server

Hello everyone, I’ve recently stumbled across PlayCanvas again and after a few days of fooling around with it I really fell in love with the editor and tools that are here. One thing that I’ve been wondering for the longest time now though is how to write a multiplayer game with an authoritative server that can still utilize all the tools of the engine.

The way I’m seeing it is that each client only ever passes basic inputs to the server and receives back position/other information. With my limited experience in 2d html game development this wasn’t so bad as it was pretty bare-bones and I was able to produce some effective results but whenever I want to move into the world of 3d and get into bigger game engines like Unity/Godot/PlayCanvas I always get lost in how to execute this model as it all seems to revolve around an entity-component system that seems pretty coupled on the client.

I’ve got 2 ideas that I just quickly thought up of on how to achieve multiplayer.
1- Create the client in the PlayCanvas editor as a project and a backend node server that uses the PlayCanvas engine and receives/emits websocket messages.
2- Create 2 PlayCanvas projects, 1 for the client and 1 as the server. Build out the same “world” in each project and run the server project for each server instance thats needed without any drawing/graphics, not sure if this is possible, kinda like Unity does it.

For #1 I feel like it would be a much longer development process as I’d have to make sure everything in the editor matched up to everything I write in code for the server, like terrain/static objects. For #2 it’s sort of the same problem, but at least I get to use the editor tools and such, and I’m not sure if it’s even possible.

I’m just trying to wrap my head around all this before I jump in and any insight into this would be much appreciated, thanks!

TANX has an authoritative server written in node.js. The server does not use the PlayCanvas engine. It’s written from scratch with no libraries/frameworks. It implements basic 2D collision but that’s about the most complex thing it does.

@devMidgard (author of BlastArena and SkyArena) is another authority in writing online multiplayer PlayCanvas games. I have a feeling he doesn’t use authoritative servers and did have problems with cheating - but I think he got around that on the client. Not 100% sure - he might want to correct me on that. :slight_smile:


Yea I saw some of your old posts on Tanx and I have considered doing it that way, but it limits what I can do in a 3d engine. Midgard is actually the one to bring me back to PlayCanvas as I’ve been following his progress in the past and saw he liked the engine, so I thought to give it a try.

I also came across some old threads about a headless mode for the engine. Has there any development on this or do you have any ideas on how to run the engine in Node without the document/drawing?

My thoughts on this is I could write both server/client logic in one project separating out logic behind if(isServer)/if(isClient) and run one instance in node as the server, while serving the client to everyone else, noting I’ve done something similar in a custom 2d engine I’ve experimented on.

Yeah, BlastArena and SkyArena run a lot of logic on the client side, however I was very heavy on anticheat algorithms for BlastArena, SkyArena is pretty much hackable but it was a tinyer project which I didn’t care much about that.

Truth is the first BlastArena Game Servers were written in C# and had all the logic running on them, but I had problems running them on Linux, so I quickly switched off to while the game had already been launched, so I had little time to bring it back up trying to loose as less revenue as possible, so I just went for client-side logic solution, and eventually got the anticheat system on the servers.

You can absolutely have PlayCanvas running alongside a Node app, I’ve been working with having the engine running on the server-side for several months now, and it runs very well.

What I did to run it was just “emulating” a fake browser inside the server app, so every document call etc calls and empty function.

I did have CPU consumption problems with a project that I still have to rework, but I do think that was merely my fault as an inexperienced JS programmer.

It’s very late right now but I might be able to share with you the node module I did to be able to run the engine on a node app, and also a tiny example on how to do so. Tho it’s a very hacky situation, so keep that in mind. I’m not a brilliant programmer either so I’m pretty sure everything can be done in better ways :slight_smile:

Currently have a very big project under development which is going to use this solution.

If you have skype, add me up; My name there is midgardh

Also, I’m glad that you decided to use PlayCanvas. It is a great engine and it’s made me recover inspiration for future web projects, I was highly frustrated with Unity, but this one is a life saver - also the live collaboration tools are amazing, if I ever manage to build a somewhat small team for my studio these tools will speed up the development process a lot.

I’ve also gone back to doing games with Unity as part of contract jobs aaand man, it does frustrate me even more than back then.


Some insight can be found in this thread (which I did read when I was planning to wrap PlayCanvas inside node): Engine - headless


Everything you just said is great news! First off, thank you very much and i’m glad to see you working on a bigger project. I wish you the best, you have been a great inspiration to my fiddling in html games for awhile now.

Ill try and read up on that post again, I had skimmed it before but never really dug into it. The node module and example app would help out a ton so thanks again, ill try and add you on Skype.

1 Like


Hey together.
I would really appreciate some kind of tutorial or guidance on how to set up that Authoriative NodeJS WebSocket Server with 3D Playcanvas games.

Did you have some progress worth sharing?
What did you do @Grubs? How did you handle it?

Thank you :slight_smile: