> For the complete documentation index, see [llms.txt](https://docs.aethercube.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aethercube.fr/developers/protocol/transport-and-handshake.md). Agents can also search and read this documentation through its [MCP server](https://docs.aethercube.fr/~gitbook/mcp).

# Transport and handshake

This page is for anyone writing a client, a bot or a monitoring tool that talks to an Aethercube server. It explains how a connection is carried, framed and admitted. The authoritative sources are the Protobuf schemas in `protocol/proto/` and the packet table in `protocol/packet_ids.md`. If this page and those files ever disagree, they win, and please tell me.

## Transport

One TCP connection, secured with **TLS 1.3**. There is no plaintext mode and no older TLS version. The server presents a certificate chain. A client trusts it through the system roots, or pins the BLAKE3 hash of the certificate's public key (`tls.spki_blake3` in a directory entry, or the hash the server logs at start).

Every message is a Protobuf message wrapped in a frame.

## Frame

All integers are big-endian.

```
+----------------+-----------+-----------+-----------------+
| frame_length   | packet_id | flags     | payload         |
| u32            | u16       | u16       | frame_length-4  |
+----------------+-----------+-----------+-----------------+
```

`frame_length` counts the packet id, the flags and the payload. It does not count itself.

| Flag             | Value | Meaning                         |
| ---------------- | ----- | ------------------------------- |
| `COMPRESSED`     | `0x1` | The payload is compressed.      |
| `HAS_EXT_HEADER` | `0x2` | Reserved. Must be 0.            |
| `BATCH`          | `0x4` | The payload is a `PacketBatch`. |

Rules:

* A frame sent by the server is at most 8 MiB. So is the size of a payload after decompression. A larger value is a protocol error. A frame sent by a client is limited much more tightly, see [Frames from the client](#frames-from-the-client).
* A compressed payload is `uncompressed_size: u32` followed by Zstandard data. The sender compresses payloads above a threshold (default 1024 bytes, `network.compression.threshold`). Smaller payloads go uncompressed.
* A batch is a `PacketBatch` message: a list of `PacketEnvelope { packet_id, payload }`. It carries several packets in one frame. Batches cannot nest.
* A packet id is allocated once and never reused. The ranges are listed in [Packet registry](https://docs.aethercube.fr/developers/protocol/packets.md).
* An unknown packet id, a malformed payload, a bad flag or a frame over the limit is a protocol error. The disconnect reason `PROTOCOL_ERROR` exists for it.

### Frames from the client

No packet a client sends needs more than a few KiB: the largest are a `PlayerInputBatch` of 10 inputs (about 0.5 KiB) and a chat line of 256 characters (about 1 KiB). So the server enforces tighter limits on what it receives:

| Phase                                                     | Largest `frame_length` | `COMPRESSED` flag                            | `BATCH` flag                |
| --------------------------------------------------------- | ---------------------- | -------------------------------------------- | --------------------------- |
| Before `ConnectionAccepted` (handshake and content phase) | 4 KiB                  | refused                                      | refused                     |
| After `ConnectionAccepted` (playing)                      | 64 KiB                 | allowed, decompressed payload at most 64 KiB | allowed, at most 64 packets |

* A frame above its limit is refused as soon as its length is read, before its bytes are buffered. The server answers `PROTOCOL_ERROR_CODE_FRAME_TOO_LARGE` and closes.
* A compressed or batched frame before `ConnectionAccepted` is answered `PROTOCOL_ERROR_CODE_INVALID_FLAGS` and closes.
* A batch of more than 64 packets is answered `PROTOCOL_ERROR_CODE_DECODE_FAILURE` and closes.
* The packets of a batch count one by one against the packet rate limit, and the batch is counted before any of its packets is parsed.
* A client compresses only above the 1024-byte threshold, and never before `ConnectionAccepted`.

The server also bounds what it buffers for a client. A client that stops reading for about 5 seconds, or lets some MiB pile up, is dropped with `TIMEOUT`, without a notice, since it could not receive one. The server does not echo `ClientKeepAlive` more than 4 times a second, or while its write buffer is full. A client sends a keep-alive every few seconds and never needs more.

## Versions

The protocol version is `1`. Client and server must match exactly, or the server answers `ConnectionRejected` with `INCOMPATIBLE_PROTOCOL`. The version is in `protocol/VERSION`.

The server also compares the hash of the material registry, the table of block materials, which both sides embed. A different hash is rejected as `INCOMPATIBLE_REGISTRY`. This is why a plugin cannot add blocks: the client would no longer agree with the server on what a block id means.

## Handshake

```mermaid
sequenceDiagram
    participant C as Client
    participant S as Server
    C->>S: ClientHello (0x0001)
    S->>C: ServerHello (0x0002)
    C->>S: ClientCapabilities (0x0003)
    Note over S: authentication
    opt client announced content_packs/1
        Note over C,S: content phase
    end
    S->>C: ConnectionAccepted (0x0004)
    S->>C: LoadingScreen (0x000A)
    S->>C: WorldInitialize (0x0100)
    Note over C,S: chunks, entities, inventory, profile
```

On failure the server sends `ConnectionRejected (0x0005)` and closes the connection.

### Messages

| Message              | Fields that matter                                                                                                                 |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| `ClientHello`        | `protocol_version`, `client_version`, `platform`, `build_id`, `session_ticket` (online mode) or `offline_username` (offline mode). |
| `ServerHello`        | `protocol_version`, `server_version`, `server_nonce`, `tick_rate` (20), `chunk_size` (32), `material_registry_hash`.               |
| `ClientCapabilities` | `supported_features`, `maximum_chunk_size`, `supports_compression`, `compression_algorithms`, `material_registry_hash`.            |
| `ConnectionAccepted` | `player_entity_id`, `player_uuid`, `display_name`, `world_id`, `server_tick`.                                                      |
| `ConnectionRejected` | `reason_code`, `message`, `retry_allowed`.                                                                                         |
| `DisconnectNotice`   | `reason`, `message`, `reconnect_allowed`.                                                                                          |

### Authentication

* **Online mode.** The ticket in `ClientHello.session_ticket` is single-use and bound to one server. The server sends it to the backend, which answers with the account. See [Backend API](https://docs.aethercube.fr/developers/backend-api/overview.md) and [Online mode, TLS and the directory](https://docs.aethercube.fr/developers/running-a-server/online-mode-tls-and-directory.md).
  * The server bounds these checks, so a crowd of fake tickets cannot tie up its backend calls: at most 32 verifications at once, and at most 4 at once for one client address. An IPv6 address counts as its /64 network, and loopback is exempt from the per-address bound. A client over a bound is rejected with `TICKET_INVALID`, the message `too many connection attempts; retry shortly` and `retry_allowed` true.
* **Offline mode.** The server accepts `offline_username` and never contacts the backend. The identity is derived from the name.

### Rejection reasons

| Code | Name                      | Meaning                                                                                          |
| ---- | ------------------------- | ------------------------------------------------------------------------------------------------ |
| 1    | `INCOMPATIBLE_PROTOCOL`   | Protocol versions differ.                                                                        |
| 2    | `INCOMPATIBLE_REGISTRY`   | Material registries differ.                                                                      |
| 3    | `TICKET_INVALID`          | The ticket is not valid.                                                                         |
| 4    | `TICKET_EXPIRED`          | The ticket is too old.                                                                           |
| 5    | `TICKET_ALREADY_CONSUMED` | The ticket was already used.                                                                     |
| 6    | `SERVER_FULL`             | `server.max_players` reached.                                                                    |
| 7    | `PLAYER_BANNED`           | The account or the address is banned. `message` gives the reason and the end of a temporary ban. |
| 8    | `SERVER_STARTING`         | The server is not ready yet.                                                                     |
| 9    | `SERVER_STOPPING`         | The server is shutting down.                                                                     |
| 10   | `CONTENT_REQUIRED`        | The server needs content packs and the client cannot take them.                                  |
| 11   | `NOT_WHITELISTED`         | The server enforces a whitelist and the player is not on it.                                     |

A client treats a code it does not know as `UNSPECIFIED` (0) and shows the `message`. `PLAYER_BANNED` and `NOT_WHITELISTED` are sent with `retry_allowed` false. The order of the checks, the texts and the files are in `protocol/access-control.md` and [Whitelist and bans](https://docs.aethercube.fr/developers/running-a-server/whitelist-and-bans.md).

### Disconnect reasons

| Code | Name              |
| ---- | ----------------- |
| 1    | `NORMAL`          |
| 2    | `KICKED`          |
| 3    | `SERVER_SHUTDOWN` |
| 4    | `TIMEOUT`         |
| 5    | `PROTOCOL_ERROR`  |
| 6    | `RATE_LIMIT`      |
| 7    | `BANNED`          |

`BANNED` is sent to a connected player who is banned, or removed from an enforced whitelist. It carries the reason in `message` and `reconnect_allowed` false.

### Feature flags

`ClientCapabilities.supported_features` lists the optional features a client supports. There is one in version 1:

| Flag              | Meaning                                                                                                                                                  |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `content_packs/1` | The client takes part in the content phase. See [Packaging and delivery](https://docs.aethercube.fr/developers/content-packs/packaging-and-delivery.md). |

## Server states and timeouts

A connection moves through these states on the server: `AWAIT_HELLO`, `AWAIT_CAPABILITIES`, `AUTHENTICATING`, `CONTENT`, `PLAYING` and `CLOSED`.

| Rule                                     | Value                                                                                                                                                                                                                        |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ClientHello` after connecting           | 5 seconds                                                                                                                                                                                                                    |
| `ClientCapabilities` after `ServerHello` | 5 seconds                                                                                                                                                                                                                    |
| Authentication                           | 10 seconds                                                                                                                                                                                                                   |
| Keep-alive                               | The client sends `ClientKeepAlive` every 10 seconds. The server answers with `ServerKeepAlive`.                                                                                                                              |
| Idle                                     | A connection with no packet for 30 seconds is dropped.                                                                                                                                                                       |
| Content phase                            | At most 10 minutes, and at most 30 seconds without a packet.                                                                                                                                                                 |
| Packets per second                       | `network.limits.max_packets_per_second` (default 500) per connection.                                                                                                                                                        |
| Connections per address                  | `network.limits.max_connections_per_address` (default 8) open, of which at most `network.limits.max_handshakes_per_address` (default 4) not in the world yet. An IPv6 address counts as its /64 network. Loopback is exempt. |
| Connections in all                       | `network.limits.max_connections` (default 1024).                                                                                                                                                                             |

A host that expects many players behind one public address (a LAN party, a school, a carrier-grade NAT) raises the per-address limits. See [server.yml reference](https://docs.aethercube.fr/developers/running-a-server/configuration-reference.md#network).

The content phase accepts only a few packets and treats any other as a protocol error. See [Packaging and delivery](https://docs.aethercube.fr/developers/content-packs/packaging-and-delivery.md).

## After admission

After `ConnectionAccepted` the server sends `LoadingScreen`, then `WorldInitialize` and the chunks around the player. Gameplay then flows in both directions. The sequences are described in the contract documents. See [Contracts](https://docs.aethercube.fr/developers/protocol/contracts.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.aethercube.fr/developers/protocol/transport-and-handshake.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
