The multiplayer feature works using an TCP-based connection, with a custom binary protocol described below.
All TCP packets are prefixed with its length, a 16 bit unsigned int (little endian).
The server sends this packet to a newly connected client, indicating its snake ID, the position of all snakes and the position of the food.
Field | Description | Size |
---|---|---|
Type | Packet type value = 0x1 | 1 byte |
YourID | Your snake ID | 1 byte |
ID | Snake identifier or food (0xff) | 1 byte |
Size | Coord sequence size (LSB) | 2 bytes |
PointX | x coordinate | 1 byte |
PointY | y coordinate | 1 byte |
PointX | x coordinate | 1 byte |
PointY | y coordinate | 1 byte |
... | ... | 1 byte |
The server sends this packet when a new food is spawned
Field | Description | Size |
---|---|---|
Type | Packet type value = 0x2 | 1 byte |
SnakeID | Snake that ate the food | 1 byte |
PointX | x coordinate | 1 byte |
PointY | y coordinate | 1 byte |
The client sends this packet to inform a direction update.
Field | Description | Size |
---|---|---|
Type | Packet type value = 0x3 | 1 byte |
Direction | The direction | 1 byte |
The server broadcasts this packet every 50ms, with the all snake heads
Field | Description | Size |
---|---|---|
Type | Packet type value = 0x4 | 1 byte |
ID | Snake identifier | 1 byte |
PointX | x coordinate | 1 byte |
PointY | y coordinate | 1 byte |
The server sends this packet to inform all the clients that a new snake connected.
Field | Description | Size |
---|---|---|
Type | Packet type value = 0x5 | 1 byte |
ID | Snake identifier | 1 byte |
Size | Coord sequence size (LSB) | 2 bytes |
PointX | x coordinate | 1 byte |
PointY | y coordinate | 1 byte |
... | ... | 1 byte |
The server sends this packet to inform a client has disconnected.
Field | Description | Size |
---|---|---|
Type | Packet type value = 0x6 | 1 byte |
SnakeID | The snake id | 1 byte |
The server sends this packet if the server is full.
Field | Description | Size |
---|---|---|
Type | Packet type value = 0x7 | 1 byte |