Skip to content

Networking: A Practical Starting Point

Multiplayer games exchange messages between clients and a server. SpiderMonkey provides client and server connections, message serialization and event listeners; game rules, state replication and security are application responsibilities.

Build a basic connection

  1. Create and start a server, then connect a client to its address and port.
  2. Define serializable message types and register them as described in the SpiderMonkey guide.
  3. Register message and connection listeners before relying on their events. Send a small message in each direction and handle disconnects.
  4. Enqueue scene-graph changes onto the application thread when they originate in network callbacks.

Use reliable messages when delivery and order matter, and consider unreliable messages for frequently refreshed state. Validate client input on the server and design for latency and reconnects. A headless server can run game logic without opening a window.