# Protocol

> What travels over the two WebSocket channels, for writing clients in other engines or debugging.

Source: https://syncverse.aqaddoura.com/docs/protocol

## Two channels

| Channel | Endpoint | Encoding | Used for |
| --- | --- | --- | --- |
| Lobby | `/master` | JSON in binary frames | Create and find rooms, room list events |
| Room | `/rooms/<id>` | Little-endian binary, 4-byte header | Players, objects, RPCs, properties |

Every frame is a binary WebSocket frame, the lobby's JSON included, because the WebGL transport ignores text frames. The current protocol version is **2**; the lobby's first frame announces it and the SDK refuses a mismatch.

## Lobby requests

Each request is a JSON object with a numeric `type` and a `reqId` that the response echoes. Room list events have no `reqId`.

**CreateRoom**

```json
{ "type": 1, "reqId": 7, "roomName": "arena", "maxPlayers": 8, "isVisible": true, "isOpen": true }
{ "type": 17, "reqId": 7, "status": 0, "room": { "id": "room-...", "server": "wss://.../rooms/room-...", "ticket": "..." } }
```

## Room frames

A room frame starts with a `u16` message type and a `u16` sender id. Object messages add a `u32` view id. Strings are UTF-8 with a `u16` length. When a socket opens, the server first sends the players present, then every buffered spawn and RPC in order, then the last state of each object.

## Full specification

Every message, field and status code is in [CONTRACT.md](https://github.com/simple-yet-efficient/syncverse-server/blob/master/CONTRACT.md) in the server repository, together with shared test vectors both implementations check against.
