Online multiplayer in 50 lines: no server, no netcode headaches
How Gamero rooms let you ship an online multiplayer web game without writing, hosting or paying for a game server.
Online multiplayer is the feature most game-jam entries skip. Not because it isn't fun, but because of everything around it: renting a server, setting up WebSockets, matchmaking, room codes, reconnecting, HTTPS certificates, and paying for all of it after the jam is over. For a weekend project, that's usually the end of the idea.
On Gamero, that part is already done. Your game talks to a tiny API in the Gamero SDK, and Gamero runs the rooms and passes messages between players. You write the game, nothing else.
What you get
- Rooms of 2 to 16 players, created on demand and gone when everyone leaves.
- Quick match into an open public room, or a private room with a 5-character code to share with friends.
- Reliable, ordered JSON messages to everyone or to one player.
- A host, picked automatically, who moves to the next player if they leave.
- Player names from Gamero accounts. Guests can play too, no sign-up needed.
- No server code, no hosting, no bill. It works in the same sandboxed iframe as every other Gamero game.
A complete multiplayer game
Here is a whole game: everyone in the room is a dot that follows their mouse or finger, and you see everyone else's dot move live. It's one index.html, no build step, under 50 lines.
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://gamero.gg/sdk/gamero.js"></script>
</head>
<body style="margin:0;background:#111">
<button id="play" style="position:fixed;top:12px;left:12px">Quick match</button>
<canvas id="c"></canvas>
<script>
const canvas = document.getElementById("c"), ctx = canvas.getContext("2d");
canvas.width = innerWidth; canvas.height = innerHeight;
const mp = Gamero.multiplayer;
const dots = {}; // player id -> { x, y }
let me = { x: 100, y: 100 };
// 1. Listen
mp.on("message", (data, from) => { dots[from.id] = data; });
mp.on("leave", (player) => { delete dots[player.id]; });
// 2. Join
document.getElementById("play").onclick = async () => {
await mp.join({ maxPlayers: 8 });
document.getElementById("play").remove();
};
// 3. Move and tell everyone where you are
const go = (e) => { me = { x: e.clientX, y: e.clientY }; };
addEventListener("pointermove", go);
addEventListener("pointerdown", go);
setInterval(() => { if (mp.room) mp.send(me); }, 50); // 20 times a second
// 4. Draw
(function draw() {
ctx.fillStyle = "#111"; ctx.fillRect(0, 0, canvas.width, canvas.height);
for (const d of Object.values(dots)) { ctx.fillStyle = "#4cc9f0"; ctx.beginPath(); ctx.arc(d.x, d.y, 14, 0, 7); ctx.fill(); }
ctx.fillStyle = "#f72585"; ctx.beginPath(); ctx.arc(me.x, me.y, 14, 0, 7); ctx.fill();
requestAnimationFrame(draw);
})();
</script>
</body>
</html>The multiplayer part is four steps:
- Load the SDK with one script tag. It defines
Gamero.multiplayer. - Listen with
mp.on("message")andmp.on("leave"), before you join. - Join with
mp.join(). Gamero finds or creates a room. - Send your state with
mp.send(). Everyone else receives it in their message handler.
Zip it, upload it as a new game, open Test play in two browser windows (or on your phone and laptop) and press Quick match in both. That's online multiplayer.
Playing with friends
Quick match is great for strangers. For friends, create a private room and show its code:
// Quick match: any open public room with the same size, or a new one
await mp.join({ maxPlayers: 4 });
// Play with friends: create a private room and show the code
const room = await mp.join({ private: true, maxPlayers: 4 });
showBig(room.code); // e.g. "K7QX2"
// Your friend types the code
await mp.join({ code: "K7QX2" });mp.room always holds the current room, including the player list, kept up to date as people join and leave, so drawing a lobby screen is a simple loop over mp.room.players.
Growing it into a real game
The dot demo lets every player broadcast their own position, which is fine for casual games. When there is something to win, you want one source of truth. Gamero gives every room a host: the host runs the rules (physics, collisions, scoring, randomness), the others only send their inputs to the host and draw what it sends back.
mp.on("message", (data, from) => {
if (data.type === "input" && mp.isHost()) inputs[from.id] = data; // host collects inputs
if (data.type === "state") latest = data; // everyone renders the host's world
});
// Host presses Start: nobody can join mid-match any more
if (mp.isHost()) { mp.lock(); mp.send({ type: "start", seed: 1234 }); }
// Game loop, at a fixed rate (not every frame)
setInterval(() => {
if (mp.isHost()) { step(inputs); mp.send({ type: "state", players: snapshot() }); }
else mp.send({ type: "input", left, right, jump }, mp.room.host);
}, 50);
// The host left? The next player takes over from the last snapshot
mp.on("host", () => { if (mp.isHost()) continueFrom(latest); });A few rules of thumb that keep it smooth:
- Send 10 to 20 times a second, not every frame. Messages are limited to 16 KB and 60 per second per player.
- Tag every message with a
typeand keep snapshots small: rounded numbers, short keys. - Smooth other players by drawing them about 100 ms in the past and interpolating between snapshots.
- Call
mp.lock()when the match starts so nobody drops in halfway. - Handle
leave,hostandclose: players disconnect, phones go to sleep. - Keep a solo or bot mode. Outside Gamero (your local dev server)
joinrejects with"unavailable", so the game should still run.
Turn-based? Even simpler: each player sends their move, the host checks it and broadcasts the result.
Leaderboards and awards still work
Multiplayer uses the same SDK as leaderboards, awards and shop items. Each player submits their own score from their own client, and Gamero shows the leaderboard next to your game.
Let your AI assistant write the netcode
Building with Claude Code, Cursor or Copilot? Open the creator guide with Online multiplayer selected and copy the prompt. It explains the whole multiplayer API, the host-authoritative pattern, the lobby screen and the edge cases, plus how to package the game into a ready-to-upload gamero.zip.
Try it this week
The next jam is a great excuse: a two-player duel, a party game for eight, a co-op puzzle. The hardest part of online multiplayer is now the fun part, the game itself.