# websocket-multiplayer-room

Run a small authoritative multiplayer room over WebSockets (join, input, server tick, state broadcast, leave) with no dependencies, and know when to move to Colyseus

- **Space:** game-dev-web-public (https://github.com/Tech-Realm/space-game-dev-web-public/tree/main/websocket-multiplayer-room)
- **Level:** L1 (as the registry reports it)
- **Keys it needs (names only):** none
- **Tools:** node
- **Routes:** node-local, colyseus; checks: 1
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use game-dev-web-public/websocket-multiplayer-room` or MCP `get_pack game-dev-web-public/websocket-multiplayer-room`
- **Files:** CHANGELOG.md, code/room.test.mjs, code/server.mjs, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, spec/SPEC.md, spec/source.md

## Purpose (spec/SPEC.md)

## Goal
Two or more browser clients see the same game state, driven by a server that owns the truth (clients send inputs, not positions).

## Steps
1. Start the server: `node code/server.mjs 8787` (Node 18+, no npm install; minimal RFC 6455 text frames).
2. Clients: `new WebSocket('ws://host:8787/room/lobby')`, send `{t:'input', dx, dy}`; receive `{t:'state', tick, players}` at 20 Hz.
3. The server clamps speed per tick (basic anti-cheat) and drops players that stop sending pings.
4. Production: move to Colyseus (MIT; rooms, schema sync, matchmaking) or WebRTC data channels for P2P, behind TLS (wss://) on our host or a Cloudflare tunnel.
5. Check: `node code/room.test.mjs` (starts the server, two clients, verifies sync).

## Edge cases
- This server handles text frames < 64 KB, no compression or fragmentation: fine for a room of a few players, not for production.
- Latency: add client-side prediction + server reconciliation when moving feels laggy.
- WebRTC needs a STUN/TURN server for players behind strict NATs.

## Don'ts
- Don't trust client positions or scores.
- Don't expose the raw ws port publicly without TLS and a rate limit.



---

Canonical URL: https://logicpacks.io/packs/game-dev-web-public/websocket-multiplayer-room

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
