RakNet

This page describes deprecated content.
This content remains available but may be removed in a future update.
Reason: Deprecated in 26.60

RakNet is a networking library and protocol for multiplayer games. It runs over UDP and provides connection management, configurable reliability and ordering, sequencing, and fragmentation.

UDP does not guarantee delivery or ordering. RakNet supports different delivery modes, so applications can request reliability or ordering when needed.

The source code for RakNet is available in the archived source repository.

Use in Bedrock Edition


NetherNet became the default transport for Bedrock Dedicated Server in 26.50. In 26.60, RakNet was deprecated, and the dedicated server's warning for connections not using NetherNet was changed to an error.

Data Types


The types below describe the packet layouts on this page. Multi-byte integers are big-endian unless stated otherwise; 24-bit indices are little-endian. Address structures have their own byte order.[1]

TypeSizeDescription
Byte1 byteUnsigned 8-bit value.
Boolean1 byte0x00 is false; 0x01 is true.
Short2 bytesSigned 16-bit integer.
Unsigned Short2 bytesUnsigned 16-bit integer.
Int4 bytesSigned 32-bit integer.
Unsigned Int4 bytesUnsigned 32-bit integer.
Long8 bytes64-bit integer. Whether it represents a signed value depends on the field.
uint24le3 bytesUnsigned 24-bit little-endian integer, used for datagram sequence numbers and frame indices.
StringVariableAn unsigned 16-bit byte length followed by that many string bytes.
Magic16 bytesThe fixed 00ffff00fefefefefdfdfdfd12345678 value used in offline packets.
Address7 bytes (IPv4);
29 bytes (IPv6)
Encodes the address family, address and port. IPv4 address bytes are inverted; the port is big-endian. IPv6 also includes address-family, flow-info and scope fields.

Handshake Sequence


The handshake begins with unconnected UDP packets and continues with connection-control messages carried inside RakNet frames.

  1. C->S: Open Connection Request 1
  2. S->C: Open Connection Reply 1 (or Incompatible Protocol)
  3. C->S: Open Connection Request 2
  4. S->C: Open Connection Reply 2. The peers can now exchange framed connection-control messages.
  5. C->S: Connection Request
  6. S->C: Connection Request Accepted
  7. C->S: New Incoming Connection

After this exchange, the RakNet connection is established. Connection Request, Connection Request Accepted, and New Incoming Connection are themselves carried inside frames. In Bedrock Edition, game packets are carried in RakNet frames as described at Game Packet.

Packets


Offline packet IDs identify UDP datagrams; connected message IDs identify the payload inside a frame. The handshake tables below describe the layout with RakNet security disabled. Optional security handshakes and connection passwords are not included. Field details can vary by implementation.

Unconnected Ping

The client sends this packet to discover a server. ID 0x01 is a regular unconnected ping; 0x02 asks for a response only when the server is accepting new connections. The server replies with Unconnected Pong.

Packet IDField NameField Type
0x01, 0x02TimeLong
MagicMagic
Client GUIDLong

Unconnected Pong

The server sends this in response to an unconnected ping. It echoes the ping time and includes its GUID and a server ID string. In Bedrock Edition, that string contains server-list information in a semicolon-delimited format; its fields can vary by game version.

Packet IDField NameField TypeNotes
0x1cTimeLong
Server GUIDLong
MagicMagic
Server ID StringStringCarries server-list information.

Connected Ping

This packet measures latency on an established connection. It is commonly sent unreliably.

Packet IDField NameField Type
0x00TimeLong

Connected Pong

The receiver replies with the original ping time and its own response time. It is commonly sent unreliably.

Packet IDField NameField Type
0x03Ping TimeLong
Pong TimeLong

Open Connection Request 1

The first packet in the handshake sequence, sent by the client to the server.

Packet IDField NameField TypeNotes
0x05MagicMagic
Protocol versionByteRakNet protocol version used by the client; separate from the Bedrock game protocol version.
PaddingZero bytesZero padding used to probe the path MTU.

The MTU is inferred from the datagram length, including IP and UDP overhead; it is not a numeric field in this request. The server replies with the selected MTU, or sends Incompatible Protocol if it does not support the client's RakNet protocol version.

Open Connection Reply 1

The second packet in the handshake sequence, sent by the server to the client.

Packet IDField NameField TypeNotes
0x06MagicMagic
Server GUIDLong
Use securityBooleanFalse for the layout shown here.
MTUUnsigned ShortSelected MTU for the connection.

Open Connection Request 2

The third packet in the handshake sequence, sent by the client to the server.

Packet IDField NameField Type
0x07MagicMagic
Server AddressAddress
MTUUnsigned Short
Client GUIDLong

Open Connection Reply 2

The fourth packet in the handshake sequence, sent by the server to the client.

Packet IDField NameField TypeNotes
0x08MagicMagic
Server GUIDLong
Client AddressAddress
MTUUnsigned Short
Encryption enabledBooleanFalse for the layout shown here.

Connection Request

The client sends this framed message after Open Connection Reply 2 to continue the RakNet handshake.

Packet IDField NameField Type
0x09GUIDLong
TimeLong
Use securityBoolean

Connection Request Accepted

The server sends this packet to accept the client's connection request.

Packet IDField NameField TypeNotes
0x10Client addressAddress
System indexUnsigned ShortSystem index assigned by the server.
Internal addressesAddress arrayInternal server addresses; the count varies by implementation, commonly 10 or 20.[2]
Request timeLongTimestamp from the corresponding Connection Request.
TimeLongServer acceptance time.

New Incoming Connection

The client sends this packet to confirm that it received the server's acceptance.

Packet IDField NameField TypeNotes
0x13Server addressAddress
Internal addressesAddress arrayInternal client addresses; the count varies by implementation, commonly 10 or 20.[3]
Ping timeLongServer acceptance timestamp echoed by the client.
Pong timeLongTime at which the client sends this message.

Disconnection Notification

This packet notifies the other peer that the sender is disconnecting.

Packet IDField NameField TypeNotes
0x15No payloadSignals that the sender is disconnecting.

Incompatible Protocol

The server sends this packet when it does not support the RakNet protocol version used by the client.

Packet IDField NameField Type
0x19ProtocolByte
MagicMagic
Server GUIDLong

Frame Set Packet

This packet carries one or more frames between connected peers.

Packet IDField NameField TypeNotes
0x80–0x9fSequence numberuint24leUsed for building ACK and NACK ranges
FramesFlagsByteTop 3 bits give the reliability type, fourth bit is 1 when the frame is fragmented and part of a compound.
Body bit lengthUnsigned ShortLength of this frame's body in bits.
Reliable frame indexuint24leOnly if reliable, used for detecting frame level duplication
Sequenced frame indexuint24leOnly if sequenced, used for discarding out-of-date packets
Order
(if ordered or sequenced)
Ordered frame indexuint24leTells the receiver the correct order in which to deliver frames to the application
Order channelByteMaximum of 32 channels
Fragment
(only if fragmented)
Compound sizeUnsigned IntNumber of fragments in the split message.
Compound IDUnsigned ShortIdentifies which compound this fragment is part of
IndexUnsigned IntZero-based index of this fragment in the split message.
Bodyceil(length/8) bytes

Frame-set datagrams use a header byte in the range 0x80–0x9f. Bit 0x80 identifies a valid datagram, while bits 0x40 and 0x20 indicate ACK and NACK packets, respectively. For frame sets, both bits are clear, and the remaining bits contain additional datagram flags. A frame set can contain multiple frames.[4]

The reliability values transmitted in the frame header are as follows:

IDNameReliableSequencedOrdered
0unreliable
1unreliable sequencedx
2reliablex
3reliable orderedxx
4reliable sequencedxx

The original RakNet API also defines receipt modes 5, 6, and 7. These are encoded as wire values 0, 2, and 3 respectively; receipt notification is handled locally.[5]

Sequenced delivery discards older packets when a newer packet has arrived. Ordered delivery preserves the order of reliable packets within a channel.

Game Packet

This Bedrock-specific message carries a batch of game packets inside a RakNet frame.

Packet IDField NameField TypeNotes
0xfeBodybytesIn Bedrock Edition, the body contains a batch of game packets. Framing and compression are described in [[mcw:Bedrock Edition protocol#Packet format|Bedrock Edition protocol]].

Packet definitions are listed at [[mcw:Bedrock Edition protocol/Packets]].

NACK

This packet reports datagrams that were not received so the sender can retransmit them when required.

Packet IDField NameField TypeNotes
0xa0Record countUnsigned ShortNumber of records in the packet
RecordsIs Single?Boolean0 indicates a range; 1 indicates a single sequence number.
No Range, if is_single == trueSequence numberuint24leDatagram sequence number in this record.
Range, if is_single == falseStart Sequence numberuint24leFirst datagram sequence number in the inclusive range.
End Sequence numberuint24leLast datagram sequence number in the inclusive range.

A NACK reports frame-set sequence numbers that were not received, prompting retransmission where required.

ACK

This packet acknowledges datagrams received from the other peer.

Packet IDField NameField TypeNotes
0xc0Record countUnsigned ShortNumber of records in the packet
RecordsIs Single?Boolean0 indicates a range; 1 indicates a single sequence number.
No Range, if is_single == trueSequence numberuint24leDatagram sequence number in this record.
Range, if is_single == falseStart Sequence numberuint24leFirst datagram sequence number in the inclusive range.
End Sequence numberuint24leLast datagram sequence number in the inclusive range.

An ACK reports frame-set sequence numbers that were received. Both ACK and NACK packets can contain multiple records.

References


  1. ↑ RakNet: BitStream go-raknet: Frame encoding
  2. ↑ "go-raknet: Connection Request Accepted"
  3. ↑ "go-raknet: New Incoming Connection"
  4. ↑ "go-raknet: Frame encoding"
  5. ↑ "RakNet: Reliability layer"