The .io architecture
- Positions — direct channel, 15–20 times per second, interpolated on
mp.now(). - Pellets — claimed with
setnx: first claim wins, the second gets a refusal. - Score — shared state with a
monotonicrule and adelta_max, so it can only go up, a little at a time. - Leaderboard —
mp.submitScore('arena', score, { periods: ['all','daily'] })at death.
const room = await mp.quickmatch({ mode: 'io', max_players: 64 });
room.on('peer', (p, from) => snakes.update(from, p));
setInterval(() => room.send(me.head()), 60);
function tryEat(pellet) {
room.setnx(`pellets.${pellet.id}`, mp.account.id);
room.inc(`players.${mp.account.id}.score`, 1);
}
room.on('rejected', () => { /* somebody got there first: that pellet is gone */ });
async function die(score) {
await mp.submitScore('arena', score, { periods: ['all', 'daily'] });
const top = await mp.leaderboard('arena', { period: 'daily', limit: 10 });
}Rooms hold up to 128 players and a game can run 2,000 live rooms, so quickmatch simply opens a new arena when one fills. Our slither demo and arena demo implement this and their source is readable in the browser.
How many players can an .io game room hold?
Up to 128 per room, and 2,000 live rooms per game. Quickmatch fills rooms and opens new ones automatically.
How do I stop two players from eating the same pellet?
Claim it with setnx. The server accepts only the first write; the second client receives a refusal it can react to.
Make your game online today
Free sandbox keys in one call, no account and no card. $19.99/month when you ship, for every game you make.
Free sandbox · $19.99/mo to go live · cancel anytime