Colyseus Realtime Tanks
Host a Colyseus 0.17 multiplayer tank game on Edgegap with one dedicated server per match, using direct connection or the Edgegap matchmaker.
Explore how to host Colyseus servers on Edgegap using techniques from the Realtime Tanks sample by the Colyseus team.
The sample has one authoritative Colyseus server and 9 clients built with different engines - Three.js, PlayCanvas, Construct 3, Godot, Unity, Defold, GameMaker, Haxe and MonoGame. Each match gets its own server, started near its players, and the server stops itself when the match is over.
This sample shows:
Colyseus 0.17 server in a
linux/amd64Docker image, listening on port2567,one server per match - the server stops its own deployment when nobody joins, when it stays empty, or after a set number of rounds,
direct mode - start a deployment and pass its URL to any of the 9 clients with
?server=or--server=,Edgegap Matchmaker (optional) - built into Three.js, Unity and Godot clients, for web and desktop builds,
one WebSocket port with TLS Upgrade - carrying both the Colyseus matchmaking HTTP request and the room WebSocket.
✔️ Preparation
Before we start, you will need:
Realtime Tanks Sample project (modified for Edgegap),
Node.js, to run the server locally and the deploy script.
Locally, the server behaves like upstream. From the server folder, run npm install then npm run dev.
⚡ Deploy and Connect
1. Build the Server Image
☑️ To get started, you'll need to create a free account with Edgegap. No credit card required.
☑️ Find your Container Registry project name and credentials.
☑️ Sign in to Edgegap's Container Registry with Docker, using your registry project name, username and token:
☑️ Build and push your server image:
☑️ Optionally, test your image locally first. ARBITRIUM_REQUEST_ID makes it act as on Edgegap - with no delete URL set, self-stop logs that and exits:
✅ You may now proceed to the next step.
2. Create an App Version
☑️ Create an application named realtime-tanks, and a version named v1 with:
image
registry.edgegap.com/<project>/realtime-tanks, tagv1,your Container Registry username and token, so Edgegap can pull your image,
resources 0.25 vCPU and 512 MB memory,
port
2567, namedgameport, protocol WS, with TLS Upgrade enabled,max duration 60 minutes for testing.
Optionally, set environment variables on your app version:
MATCH_ROUNDS- end the match after this many won rounds (default0, an endless arena),FIRST_JOIN_TIMEOUT_S- seconds before a server nobody joined stops itself (default120),EMPTY_TIMEOUT_S- seconds before a server everyone left stops itself (default30).
✅ You may now proceed to the next step.
3. Connect Directly
☑️ Start a server near you with the sample's deploy script. Your Edgegap API token stays on your machine:
The script prints wss://<request_id>.pr.edgegap.net:<port> and how to pass it to each client.
☑️ Pass the URL to your clients:
Three.js, PlayCanvas, Construct 3 -
?server=wss://...in the page URL,Godot -
--server=wss://...(after--in the editor's main run args), web export?server=wss://...,Unity -
--server=wss://...on the command line, WebGL?server=wss://..., or theserverUrlfield,Defold - HTML5
?server=wss://..., native--config=tanks.server_url=wss://...or[tanks] server_urlingame.project,GameMaker -
--server=wss://...on the command line, HTML5?server=wss://...,Haxe - JS
?server=wss://..., HashLink--server=wss://...,MonoGame -
--server=wss://...orTANKS_SERVER_URLenvironment variable.
🙌 Congratulations on your first Deployment on Edgegap!
4. Add the Matchmaker (Optional)
☑️ Open Matchmaker page in dashboard, click Create, and upload edgegap/matchmaker-config.json from the sample.
The config has one casual profile for 2 to 8 players per match. After 15 seconds, it starts a match with whoever is waiting, with at least 2 players.
☑️ Add every origin serving your game to allowed_cors_origins, as browser builds call the matchmaker from the page (see CORS). The config allows http://localhost:5173 (Vite), http://localhost:8060 (Godot web) and http://localhost:8080.
☑️ Click Create and Start. Once your matchmaker shows Online, copy its API URL and Auth Token.
☑️ Start your clients with matchmaker settings:
Three.js -
http://localhost:5173/?mm=<API URL>&mmToken=<Auth Token>, orVITE_MM_URL/VITE_MM_TOKENin.env.local,Unity -
--mm=<API URL> --mm-token=<Auth Token>, WebGL?mm=...&mmToken=..., or Edgegap Matchmaker fields onGameManager,Godot -
-- --mm=<API URL> --mm-token=<Auth Token>, web export?mm=...&mmToken=....
☑️ Open two clients - matchmaking needs at least 2 players, and they can use different engines.
Each client shows "Searching for players..." and connects once a server is assigned. A server setting always takes priority over the matchmaker.
🙌 Congratulations on your first matchmade Deployment on Edgegap!
🔄 Match Lifecycle
Client creates a ticket with
POST /ticketsforcasualprofile, then checks it every 2 seconds withGET /tickets/{id}.Matchmaker deploys
realtime-tanksnear the players. When the ticket reachesHOST_ASSIGNED, the client reads the assignment's FQDN and external port ofgameport.Client joins
wss://<fqdn>:<port>. A freshly started server can answer 502 for a few seconds, so clients retry joining for up to 20 seconds (see Connect to Server).Server calls
ARBITRIUM_DELETE_URLto stop its own deployment when nobody joined withinFIRST_JOIN_TIMEOUT_S, when everyone left forEMPTY_TIMEOUT_S, or whenMATCH_ROUNDSrounds have been won. Your app version's max duration is the backstop.
The matchmaker client is small and has no dependencies, so it ports easily to other clients - see web-threejs/src/Matchmaker.ts, unity/Assets/Scripts/EdgegapMatchmaker.cs and godot/scripts/edgegap_matchmaker.gd.
See Matchmaking and Deployments to learn more.
🚀 Going Further
Validate joiners - matchmaker deployments get
MM_TICKET_IDS. Have clients pass their ticket ID in join options and check it inonAuth, so only matched players can join.Before launch - set
inspecttofalsein your matchmaker config, list your real origins, and raise max duration to fit your matches (see Before Going Live).
⚠️ Known Issues
Tested end to end on Edgegap with Colyseus 0.17, matchmaker 3.3.2, Godot 4.5.2 and Unity 6000.3:
direct - Node Colyseus clients and Godot desktop client joined a deployment over
wss://, and the server stopped itself after everyone left,matchmaker - Three.js in browser and Godot desktop client were matched onto one server, then Three.js and a Unity Windows build.
Construct 3, Defold, GameMaker, Haxe and PlayCanvas
serveroverrides, Godot web export and Unity WebGL are not tested yet.
Last updated
Was this helpful?

