Relay message protocol
Understand how the Relay message protocol transmits data between clients and servers in the Relay service.
Read time 10 minutesLast updated 14 hours ago
If you’re using the Relay SDK with UTP or with NGO for your project, the Relay message protocol is already supported. However, if you want to use an alternative engine or networking solution, you’ll need to implement the Relay message protocol before using it. Use the Relay message protocol specifications to implement the Relay message protocol. The Relay message protocol expects you to express field values in big-endian order, also known as the “network order,” where the most significant byte occurs first. Messages aren't authenticated except for the
BINDMessage types
| Code | Name | Description |
| | A |
| | A |
| | A |
| | A |
| Reserved. | |
| Reserved. | |
| | An |
| Reserved. | |
| Reserved. | |
| | A |
| | A |
| | A |
| | An |
Accept mode types
The accept mode defines how a Relay server handles requests from clients trying to connect. Relay only supports theAUTOAUTO| Code | Name | Description |
| | |
| Reserved. |
Standard header
All message types share a standard header that has a signature, the Relay message protocol version, and the message contained in the body of the packet.| Bytes | 1 .. 2 | 3 | 4 |
| Purpose | | | |
| Field | Type | Description |
| []byte | The |
| uint8 | The |
| uint8 | The |
Message bodies
BIND message
BINDBINDBINDBINDBINDNonce| Bytes | 1 .. 4 | 5 | 6 .. 7 | 8 | 9 .. N | N+1 .. 33 |
| Purpose | Header (Type 0) | | | | | |
BIND| Field | Type | Description |
| uint8 | |
| uint16 | |
| uint8 | |
| []byte | |
| [32]byte | |
Security
You must sign the HMAC with the secret key returned from the Allocations service. If the HMAC is invalid, the Relay server silently rejects theBIND messageBIND messageBIND_RECEIVED message
Relay servers sendBIND_RECEIVEDBIND messageCONNECT_REQUEST message| Bytes | 1 .. 4 |
| Purpose | Header (Type 1) |
PING message
PINGPING
Each
PINGPINGPING| Bytes | 1 .. 4 | 5 .. 20 | 21 .. 22 |
| Purpose | Header (Type 2) | | |
PING| Field | Type | Description |
| [16]byte | |
| uint16 | |
CONNECT_REQUEST message
CONNECT_REQUESTToConnectionData| Bytes | 1 .. 4 | 5 .. 20 | 21 | 22 .. |
| Purpose | Header (Type 3) | | | |
CONNECT_REQUEST| Field | Type | Description |
| [16]byte | |
| uint8 | |
| []byte | |
ACCEPTED message
A Relay server sends anACCEPTED| Bytes | 1 .. 4 | 5 .. 20 | 21 .. 36 |
| Purpose | Header (Type 6) | | |
ACCEPTED| Field | Type | Description |
| [16]byte | |
| [16]byte | |
DISCONNECT message
TheDISCONNECTCONNECT_REQUESTDISCONNECTDISCONNECTDISCONNECTERROR messageRELAYCONNECT_REQUEST message| Bytes | 1 .. 4 | 5 .. 20 | 21 .. 36 |
| Purpose | Header (Type 9) | | |
DISCONNECT| Field | Type | Description |
| [16]byte | |
| [16]byte | |
RELAY message
RELAYRELAYFromAllocationIDBIND messageErrClientPlayerMismatchERRORCONNECT_REQUESTErrNotConnectedERROR messageToAllocationIDFromAllocationID| Bytes | 1 .. 4 | 5 .. 20 | 21 .. 36 | 37 .. 38 | 39 .. |
| Purpose | Header (Type 10) | | | | |
The following table describes each field found in a
RELAY| Field | Type | Description |
| [16]byte | |
| [16]byte | |
| uint16 | |
| []byte | |
CLOSE message
CLOSECLOSECLOSECLOSEERRORCLOSECLOSECLOSEBINDPING| Bytes | 1 .. 4 | 5 .. 20 |
| Purpose | Header (Type 11) | |
CLOSE| Field | Type | Description |
| [16]byte | |
ERROR message
Relay servers useERROR| Bytes | 1 .. 4 | 5 .. 20 | 21 |
| Purpose | Header (Type 12) | | |
ERROR| Field | Type | Description |
| [16]byte | |
| uint8 | |
Error codes
The following table describes each of the possible error messages a Relay server can send to a client.| Code | Name | Description |
| Invalid protocol version ( | |
| Player timed out due to inactivity ( | |
| Unauthorized ( | |
| Allocation ID client mismatch ( | |
| Allocation ID not found ( | |
| Not connected ( | |
| Self-connect not allowed ( | |