Overview
NOX network communication system for managing connections between clients and servers
The Relay Protocol is a network communication system used by NOX to manage connections between clients and servers.
It uses both TCP and UDP to provide connection compatibility for clients.
General Architecture
The NOX Relay works as an intelligent proxy server that:
- Receives TCP and UDP connections from clients
- Routes messages between connected clients
- Handles authentication and sessions
Packet Format
All packets follow a common structure:
Base Structure
For clarity, the base structures are presented in the format below, The explanation of the format is detailed at the bottom of the page.
[length: ushort]
[uid: ushort]
[type: byte]
[payload: byte[]]Detailed Structure
| Type | Name | Description |
|---|---|---|
| ushort | Length | Total packet size (includes Length) |
| ushort | UID | Unique identifier (optional) |
| byte | Type | Request/response type |
| byte[] | Payload | Message data |
Important Constants
- Protocol version:
1 - Max packet size:
1024 bytes - Default port:
23032 - Connection timeout:
15 seconds - Keep-alive interval:
5 seconds - Segmentation timeout:
30 seconds
Unique Identifier (UID)
The UID field allows a callback for a specific request.
If the message comes from the server, the client must reply with the same UID.
And the UID 0x0000 to indicate that it does not expect a response, or by default.
Timeout and Keep-Alive
The timeout is reset on every received valid packet. When no packets are to be sent, the client must send a packet (e.g. Latency) within a delay shorter than the timeout value to keep the connection active. The client is responsible for sending keep-alive.
Communication Flow Example
- Handshake: The client initiates the connection with a Handshake message.
- Authentication: The client authenticates with an Authentication message.
- Session: To obtain information about an instance.
- Enter: To join an instance.
- Disconnect: For a clean disconnection, the client is automatically removed from the sessions it is connected to.
Priority System
The protocol uses a priority system to optimize performance:
- Critical: Handshake, Disconnect
- High: Authentication, Enter/Quit
- Normal: Transform, Status
- Low: Custom messages (these packets may be delayed or lost in case of congestion)
Security
- Protocol validation during the handshake
- Authentication required before any action (unless the server is in offline mode)
- Size limitation of packets (1024 bytes max, or customized by the server)
Message Types (Client → Server)
The protocol supports the following message types that clients can send to the server:
| Type | Name | Description | Priority |
|---|---|---|---|
| 0x00 | Disconnect | Clean disconnection | Critical |
| 0x01 | Handshake | Connection initialization | Critical |
| 0x02 | Segmentation | Fragmentation of large messages | Normal |
| 0x03 | Reliable | Reliable messages | Normal |
| 0x04 | Latency | Latency test | Normal |
| 0x05 | Authentication | Identity validation | High |
| 0x06 | Enter | Join an instance | High |
| 0x07 | Quit | Leave an instance | High |
| 0x08 | Custom | Custom messages | Normal |
| 0x09 | PasswordRequirement | Password request | High |
| 0x0A | Traveling | Movement between instances | Normal |
| 0x0B | Transform | Real-time position/rotation | Normal |
| 0x0C | Teleport | Instant teleportation | High |
| 0x0D | AvatarChanged | Avatar change | Normal |
| 0x0E | ServerConfig | Server configuration | High |
| 0x0F | AvatarParams | Avatar parameters | Normal |
| 0x11 | Sessions | Provides session information | Normal |
Response Types (Server → Client)
The server uses a different set of types for its responses and notifications:
| Type | Name | Description | Origin |
|---|---|---|---|
| 0x00 | Disconnect | Disconnection confirmation/notification | Response |
| 0x01 | Handshake | Handshake confirmation | Response |
| 0x02 | Segmentation | Response fragmentation | Response |
| 0x03 | Reliable | Reliable responses | Response |
| 0x04 | Latency | Latency test response | Response |
| 0x05 | Authentication | Authentication result | Response |
| 0x06 | Enter | Instance enter result | Response |
| 0x07 | Quit | Leave confirmation | Response |
| 0x08 | Custom | Custom responses | Response |
| 0x09 | PasswordRequirement | Password response | Response |
| 0x0A | Traveling | Travel confirmation | Response |
| 0x0B | Transform | Position synchronization | Response/Notification |
| 0x0C | Teleport | Teleportation confirmation | Response |
| 0x0D | AvatarChanged | Avatar change notification | Response/Notification |
| 0x0E | ServerConfig | Config change notification | Response/Notification |
| 0x0F | AvatarParams | Avatar parameters notification | Response/Notification |
| 0x10 | Join | Player arrival notification | Notification |
| 0x11 | Leave | Player departure notification | Notification |
| 0x12 | Sessions | Session information | Response |
Important information:
- Responses: Messages sent in direct reaction to a client request (same UID)
- Notifications: Automatic messages sent by the server (UID = 0x0000)
Each message type has its own detailed documentation page with its specific input and output formats.
Data Types
The protocol uses several data types to structure messages. Here are the supported types:
| Type | Size (bytes) | Description |
|---|---|---|
byte | 1 | 8-bit unsigned integer |
short | 2 | 16-bit signed integer (big-endian) |
ushort | 2 | 16-bit unsigned integer (big-endian) |
int | 4 | 32-bit signed integer (big-endian) |
uint | 4 | 32-bit unsigned integer (big-endian) |
long | 8 | 64-bit signed integer (big-endian) |
ulong | 8 | 64-bit unsigned integer (big-endian) |
float | 4 | Single-precision floating point number (big-endian) |
double | 8 | Double-precision floating point number (big-endian) |
string | 2 + N | UTF-8 string with a length prefix (ushort) |
DateTime | 8 | Unix timestamp in milliseconds |
Vector3 | 12 | 3 float components (X, Y, Z) |
Quaternion | 16 | 4 float components (X, Y, Z, W) |
byte[] | N | Byte array |
Enum | Variable | Enumeration/Flags (depending on the underlying type) |
Important Notes
- Byte order: All multi-byte types use big-endian order (most significant byte first)
- Strings: Encoded in UTF-8 with a
ushortprefix indicating the length - Timestamps: Stored as Unix timestamps in milliseconds (long)
- Enumerations: Serialized according to their underlying type (
byte,ushort,uint)
In the protocol, reading is done byte by byte. Therefore some data types are not allowed, such as booleans, which must be converted to a byte or to flags with other booleans.
Packet Syntax in the Documentation
Each message in the documentation is presented with a clear syntax for the packet format.
[Length: ushort]
[UID: ushort]
[Type: byte]
[Payload?: byte[]]
(0x01 in Type ? [Reason?: string])
(Latency == Type ? (
[ClientTimestamp: DateTime]
[ServerTimestamp: DateTime]
))Each field is described as an entry between brackets [] with the field name and its type.
When a field is optional, a ? is added before the :.
When a list of fields is grouped, they are placed between parentheses ().
Likewise, when there is a condition, the same syntax is used (Condition ? [Field]) or (Condition1 ? [Field1] : [Field2]).
Fields are listed in order of appearance in the packet.