Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:RakNet: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{MC/Exclusive|bedrock}}
{{Exclusive|bedrock}}
'''RakNet'''<ref>http://www.jenkinssoftware.com/</ref> is a networking library used by ''[[Minecraft:Bedrock Edition]]''. This documentation is based on the old [[Minecraft:Pocket Edition protocol|''Pocket Edition'' protocol]] and may be incomplete or outdated.
The source code for the RakNet Library can be found [https://github.com/OculusVR/RakNet/ here].
RakNet uses {{MC/W|User Datagram Protocol|UDP}} as its networking protocol. The key differences from TCP are that not all packets are guaranteed to reach the destination at all or in order (it isn't reliable) and it uses messages with a specified length instead of streams of data. RakNet compensates for the out-of-order delivery and makes it reliable.


'''RakNet''' is a networking library and protocol for multiplayer games. It runs over [[Minecraft:wikipedia:User_Datagram_Protocol|UDP]] and provides connection management, configurable reliability and ordering, sequencing, and fragmentation.
[[Minecraft:wikipedia:User_Datagram_Protocol|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 [https://github.com/facebookarchive/RakNet archived source repository].
== Use in Bedrock Edition ==
[[Minecraft:NetherNet]] became the default transport for [[Minecraft:Bedrock Dedicated Server]] in [[Minecraft:26.50]].<ref>{{cite|url=https://www.minecraft.net/en-us/article/minecraft--bedrock-edition-26-50-changelog|title=Minecraft: Bedrock Edition 26.50 Changelog|website=Minecraft.net}}</ref> RakNet is deprecated in [[Minecraft:26.60]], which removes client support for it.<ref>{{cite|url=https://feedback.minecraft.net/hc/en-us/articles/48740748263565-Minecraft-Beta-Preview-26-60-22-23|title=Minecraft Beta & Preview - 26.60.22/23|website=Minecraft Feedback}}</ref>
== Libraries ==
== Libraries ==
'''NOTE:'''
 
You may want to use an existing library if one exists for your language of choice.
The following libraries implement RakNet. Supported features and protocol versions vary between implementations.
Here is an incomplete list. Not all of these are maintained or complete. If these are outdated you may need to change the protocol version to 11 before it can work. The protocol doesn't seem to have had any significant changes since the official implementation was discontinued in 2014, so as long as you bump the protocol version older libraries are likely to still work.


{| class="wikitable sortable" style="width: auto; text-align: center;"
{| class="wikitable sortable" style="width: auto; text-align: center;"
Line 15: Line 20:
  ! Language
  ! Language
  ! License
  ! License
! Active development
  |-
  |-
  ! [https://github.com/sandertv/go-raknet go-raknet]
  ! [https://github.com/sandertv/go-raknet go-raknet]
  | Network System used for [https://github.com/df-mc/dragonfly Dragonfly] written in Go.
  | style="text-align: left;" | RakNet implementation written in Go.
  | Golang
  | Go
  | MIT
  | MIT
| Yes
  |-
  |-
  ! [https://github.com/netrexmc/raknet RakNet]
  ! [https://github.com/NetrexMC/RakNet RakNet]
  | RakNet implementation written in Rust.
  | style="text-align: left;" | Asynchronous RakNet implementation written in Rust.
  | Rust
  | Rust
  | Apache License
  | Apache-2.0
| No
  |-
  |-
  ! [https://github.com/PieMC-Dev/PieRakNet PieRakNet]
  ! [https://github.com/PieMC-Dev/PieRakNet PieRakNet]
  | Network System used for [https://github.com/PieMC-Dev/PieMC PieMC] written in Python.
  | style="text-align: left;" | RakNet implementation written in Python.
  | Python
  | Python
  | GPL-3
  | GPL-3.0
| Yes
  |-
  |-
  ! [https://github.com/NukkitX/Network NukkitX Network]
  ! [https://github.com/CloudburstMC/Network Cloudburst Network]
  | Network components used within NukkitX, but with great support for general use as well.
  | style="text-align: left;" | Network components used by CloudburstMC projects.
  | Java
  | Java
  | Apache License
  | Apache-2.0
| Yes
  |-
  |-
  ! [https://github.com/Podrum/rak_net rak-net]
  ! [https://github.com/Podrum/rak_net rak-net]
  | rak-net is the first updated and fully working RakNet implementation written in Python to run a Minecraft Bedrock Edition server. This library was mainly created for Podrum, although it can be used in other projects too and can be installed via pip.
  | style="text-align: left;" | Python RakNet implementation originally developed for Podrum.
  | Python
  | Python
  | GPL
  | GPL-2.0
| No
  |-
  |-
  ! [https://github.com/JRakNet/JRakNet JRakNet]
  ! [https://github.com/whirvis/JRakNet JRakNet]
  | JRakNet is a networking library for Java which implements the UDP based protocol RakNet.
  | style="text-align: left;" | Java implementation of the RakNet protocol.
  | Java
  | Java
  | MIT
  | MIT
| No
  |-
  |-
  ! [https://github.com/yesdog/netty-raknet netty-raknet]
  ! [https://github.com/yesdog/netty-raknet netty-raknet]
  | High performance implementation of RakNet for netty, following strict netty patterns.
  | style="text-align: left;" | RakNet implementation for Netty.
  | Java
  | Java
  | MIT
  | MIT
| No
  |-
  |-
  ! [https://github.com/jython234/JRakLibPlus JRakLibPlus]
  ! [https://github.com/alejzeis/JRakLibPlus JRakLibPlus]
  | A library for easy creation of RakNet servers, based on RakLib and JRakLib.
  | style="text-align: left;" | RakNet server library based on RakLib and JRakLib.
  | Java
  | Java
  | LGPL
  | LGPL-3.0
  | No
  |-
|-
  ! [https://github.com/pmmp/RakLib RakLib]
  ! [https://github.com/pmmp/RakLib RakLib]
  | RakNet server implementation written in PHP. This library is very lightweight on actual implementation - it provides the bare minimum to get a Minecraft Pocket Edition server functional. It only currently provides server functionality, and does not support most RakNet features.
  | style="text-align: left;" | Lightweight PHP RakNet server implementation.
  | PHP
  | PHP
  | GPL
  | GPL-3.0
  | Yes
  |-
|-
  ! [https://www.npmjs.com/package/raknet/ raknet]
  ! [https://www.npmjs.com/package/raknet/ raknet]
  | UDP network library that follows the RakNet protocol for Node.js.
  | style="text-align: left;" | UDP networking library for Node.js that follows the RakNet protocol.
  | Javascript
  | JavaScript
  | MIT
  | MIT
| No
  |-
  |-
  ! [https://pypi.org/project/PyRakLib/ PyRakLib]
  ! [https://pypi.org/project/PyRakLib/ PyRakLib]
  | PyRakLib is a networking library that follows the RakNet protocol for MCPE. It is ported from the PHP library RakLib.  
  | style="text-align: left;" | Python port of RakLib that follows the RakNet protocol.
  | Python
  | Python
  | GPL
  | GPL
  | No
  |-
|-
  ! [https://github.com/b23r0/rust-raknet rust-raknet]
  ! [https://github.com/b23r0/rust-raknet rust-raknet]
  | RakNet Protocol implementation by Rust.  
  | style="text-align: left;" | RakNet implementation written in Rust.
  | Rust
  | Rust
  | MIT
  | MIT
| No
  |-
  |-
|[https://github.com/SerenityJS/Baltica Baltica]
! [https://github.com/SerenityJS/Baltica Baltica]
|Baltica is a toolkit for Minecraft Bedrock Edition that includes packages for Xbox authentication and RakNet protocol implementation.
| style="text-align: left;" | Bedrock toolkit that includes a RakNet implementation.
|TypeScript
| TypeScript
|None
| See repository
|Yes
|-
|-
  ! [https://github.com/mfdgaming/raknet.py RakNet.Py]
  ! [https://github.com/mfdgaming/raknet.py RakNet.Py]
  | Mojang RakNet Protocol version 5 implementation in Python intended for use with MCPE Alpha versions.
  | style="text-align: left;" | RakNet implementation written in Python.
  | Python
  | Python
  | GPL
  | GPL-2.0
| No
  |-
  |-
![https://github.com/LavishMC/LavishRakNet LavishRakNet]
! [https://github.com/LavishMC/RakNet LavishMC RakNet]
|Custom implementation of RakNet made for game client and server.
| style="text-align: left;" | C++ fork of the original RakNet implementation.
|C++
|MIT
|Yes
|-
! [https://github.com/facebookarchive/RakNet Raknet] (official)
| The official implementation. Outdated and mostly for reference purposes. May not work with the latest Bedrock.
  | C++
  | C++
  | BSD
  | BSD
  | No
  |-
! [https://github.com/facebookarchive/RakNet RakNet (original)]
| style="text-align: left;" | Original C++ RakNet implementation.
| C++
| BSD-2-Clause
  |}
  |}


== Data types ==
== 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.<ref>[https://github.com/facebookarchive/RakNet/blob/master/Source/BitStream.h RakNet: BitStream] [https://github.com/Sandertv/go-raknet/blob/master/packet.go go-raknet: Frame encoding]</ref>


{| class="wikitable"
{| class="wikitable"
|-
! Type !! Size !! Description
!
|-
! Size (Bytes)
! Byte
! Range
| 1 byte
! Notes
| Unsigned 8-bit value.
|-
|-
! byte
! Boolean
| 1
| 1 byte
| 0 to 255
| {{cd|0x00}} is false; {{cd|0x01}} is true.
|
|-
|-
! Short
! Long
| 2 bytes
| 8
| Signed 16-bit integer.
| -2^63 to 2^63-1
|-
| Signed 64-bit Integer
! Unsigned Short
|-
| 2 bytes
! Magic
| Unsigned 16-bit integer.
| 16
|-
| <code>00ffff00fefefefefdfdfdfd12345678</code>
! Int
| Always those hex bytes, corresponding to RakNet's default OFFLINE_MESSAGE_DATA_ID
| 4 bytes
|-
| Signed 32-bit integer.
! short
|-
| 2
! Unsigned Int
| -32768 to 32767
| 4 bytes
|
| Unsigned 32-bit integer.
|-
|-
! unsigned short
! Long
| 2
| 8 bytes
| 0 to 65535
| 64-bit integer. Whether it represents a signed value depends on the field.
|  
|-
|-
! uint24le
! string
| 3 bytes
| unsigned short + string
| Unsigned 24-bit little-endian integer, used for datagram sequence numbers and frame indices.
| N/A
|-
| class="col3" | Prefixed by a short containing the length of the string in characters. It appears that only the following ASCII characters can be displayed: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
! String
|-
| Variable
! boolean
| An unsigned 16-bit byte length followed by that many string bytes.
| 1
|-
| 0 to 1
! Magic
| True is encoded as <code>0x01</code>, false as <code>0x00</code>.
| 16 bytes
|-
| The fixed {{cd|00ffff00fefefefefdfdfdfd12345678}} value used in offline packets.<ref>[https://github.com/facebookarchive/RakNet/blob/master/Source/RakPeer.cpp RakNet: RakPeer.cpp]</ref>
! address
|-
| 7 or 29
! Address
|
| 7 bytes (IPv4);<br/>29 bytes (IPv6)
| 1 byte for the IP version (4 or 6), followed by (for IPv4) 4 bytes for the IP and an unsigned short for the port number or (for IPv6) an unsigned short for the address family, an unsigned short for the port, 4 bytes for the flow info, 16 bytes for address and 4 bytes for scope id
| 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.<ref name="address-format">[https://github.com/Sandertv/go-raknet/blob/master/internal/message/addr.go go-raknet: Address encoding]</ref>
|-
|}
! uint24le
| 3
|
| 3-byte little-endian unsigned integer
|-
! Int
| 4
| -2147483648 to 2147483647
| Signed little-endian 32-bit Integer
|}


== Handshake sequence ==
== Handshake sequence ==
The handshake begins with unconnected UDP packets and continues with connection-control messages carried inside RakNet frames.<ref>[https://github.com/facebookarchive/RakNet/blob/master/Source/RakPeer.cpp RakNet: RakPeer.cpp] [https://github.com/Sandertv/go-raknet/tree/master/internal/message go-raknet: Connection messages]</ref>


# C→S: [[#Open Connection Request 1|Open Connection Request 1]]
# C→S: [[#Open Connection Request 1|Open Connection Request 1]]
# S→C: [[#Open Connection Reply 1|Open Connection Reply 1]]
# S→C: [[#Open Connection Reply 1|Open Connection Reply 1]] (or [[#Incompatible Protocol|Incompatible Protocol]])
# C→S: [[#Open Connection Request 2|Open Connection Request 2]]
# C→S: [[#Open Connection Request 2|Open Connection Request 2]]
# S→C: [[#Open Connection Reply 2|Open Connection Reply 2]]
# S→C: [[#Open Connection Reply 2|Open Connection Reply 2]]. The peers can now exchange framed connection-control messages.
 
From here on, the RakNet connection is established and all RakNet messages are contained in a [[#Frame Set Packet|Frame Set Packet]].
 
# C→S: [[#Connection Request|Connection Request]]
# C→S: [[#Connection Request|Connection Request]]
# S→C: [[#Connection Request Accepted|Connection Request Accepted]]
# S→C: [[#Connection Request Accepted|Connection Request Accepted]]
# C→S: [[#New Incoming Connection|New Incoming Connection]]
# C→S: [[#New Incoming Connection|New Incoming Connection]]


Next packets should be [[#Game Packet|Game Packet]]
After this exchange, the RakNet connection is established. Connection Request, Connection Request Accepted, and New Incoming Connection are themselves carried inside frames. In [[Minecraft:Bedrock Edition]], game packets are carried in RakNet frames as described at [[#Game Packet|Game Packet]].


== Packets ==
== 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.<ref>[https://github.com/facebookarchive/RakNet/blob/master/Source/MessageIdentifiers.h RakNet: Message identifiers] [https://github.com/Sandertv/go-raknet/blob/master/packet.go go-raknet: Frame encoding]</ref>


=== Unconnected Ping ===
=== Unconnected Ping ===
The client sends this packet to discover a server. ID {{cd|0x01}} is a regular unconnected ping; {{cd|0x02}} asks for a response only when the server is accepting new connections. The server replies with [[#Unconnected Pong|Unconnected Pong]].
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
  ! Field Name
  ! Field Name
  ! Field Type
  ! Field Type
! Notes
  |-
  |-
  |rowspan="3"| 0x01, 0x02
  |rowspan="3"| 0x01, 0x02
  | Time
  | Time
  | Long
  | Long
|
  |-
  |-
  | MAGIC
  | Magic
| magic
  | Magic
  |  
  |-
  |-
  | Client GUID
  | Client GUID
  | Long
  | Long
|
  |}
  |}


This is the first RakNet message sent by the client to a RakNet server. <code>0x01</code> is sent almost every second if the client is on the server list menu and every 4-5 seconds if the client is in-game.
=== Unconnected Pong ===
<code>0x02</code> is only replied to if there are open connections to the server. '''Note:''' as of 0.15.6 it seems that the game refreshes it's LAN world list every 4-5 seconds, however it seems the game will still ping in 1 second intervals.<br>
 
This packet should be responded to with 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 [[Minecraft:Bedrock Edition]], that string contains server-list information in a semicolon-delimited format; its fields can vary by game version.


=== Unconnected Pong ===
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 235: Line 211:
  |  
  |  
  |-
  |-
  | MAGIC
  | Magic
  | magic
  | Magic
  |  
  |  
  |-
  |-
  | Server ID string
  | Server ID String
  | string
  | String
  | Used for the MOTD. See below for details.
  | Carries server-list information.
  |}
  |}


Unconnected Pong message is sent by the server to the client in response to the Unconnected Ping message. It contains various data that is sent to the client such as MOTD, number of players, max player count, etc. The format is given below:
=== Connected Ping ===
 
'''Server ID string format'''
 
For Minecraft Bedrock this is separated by semicolons and uses the following format:<br>
<code>Edition (MCPE or MCEE for Education Edition);MOTD line 1;Protocol Version;Version Name;Player Count;Max Player Count;Server Unique ID;MOTD line 2;Game mode;Game mode (numeric);Port (IPv4);Port (IPv6);</code><br>
Example:<br>
<code>MCPE;Dedicated Server;390;1.14.60;0;10;13253860892328930865;Bedrock level;Survival;1;19132;19133;</code><br>
Result:<br>
[[File:Server ID_String Example.png]]
 
The Game mode and Game mode (numeric) values seem to not be used by the client.


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


{| class="wikitable"
{| class="wikitable"
Line 263: Line 228:
  ! Field Name
  ! Field Name
  ! Field Type
  ! Field Type
! Notes
  |-
  |-
  | 0x00
  | 0x00
  | Time
  | Time
  | Long
  | Long
|
  |}
  |}


This is the first packet sent in the Encapsulated Frame Set Packet by the client to the server. It is sent with the reliability type Unreliable so it can be handled immediately by the server.
=== Connected Pong ===
It is used for calculating the average ping between the client and the server.
 
The receiver replies with the original ping time and its own response time. It is commonly sent unreliably.


=== Connected Pong ===
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
  ! Field Name
  ! Field Name
  ! Field Type
  ! Field Type
! Notes
  |-
  |-
  |rowspan="2"| 0x03
  |rowspan="2"| 0x03
  | Ping Time
  | Ping Time
  | Long
  | Long
|
  |-
  |-
  | Pong Time
  | Pong Time
  | Long
  | Long
|
  |}
  |}


Connected Pong message is sent in response to the Connected Ping message with reliability type set to Unreliable so it can be handled immediately by the client.
=== Open Connection Request 1 ===
 
The first packet in the handshake sequence, sent by the client to the server.


=== Open Connection Request 1 ===
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 302: Line 263:
  |rowspan="3"| 0x05
  |rowspan="3"| 0x05
  | Magic
  | Magic
  | MAGIC
  | Magic
  |  
  |  
  |-
  |-
  | Protocol version
  | Protocol version
  | byte
  | Byte
  | Currently 11
  | RakNet protocol version used by the client; separate from the Bedrock game protocol version.
  |-
  |-
  | MTU
  | Padding
  | Zero padding
  | Zero bytes
  | The MTU sent in the response appears to be somewhere around the size of this padding + 46 (28 udp overhead, 1 packet id, 16 magic, 1 protocol version). This padding seems to be used to discover the maximum packet size the network can handle.
  | Zero padding used to probe the path [[Minecraft:wikipedia:Maximum_transmission_unit|MTU]].
  |}
  |}


The client sends these to the target server with ever decreasing MTU until the server responds. This is used to discover the MTU size for the connection. According to the official docs, "The MTU size is the maximum size of a packet RakNet will generate", and "if you set the MTU size larger than your or any router along the network path takes, then the network will split the packet at best, or drop it at worst", so this process of sending decreasingly padded packets (compensating for the size of the packet itself and UDP overhead, which together make 46 bytes) seem to be used to discover the maximum packet size the network can handle. See the [http://www.jenkinssoftware.com/raknet/manual/programmingtips.html official documentation page] for more info about the MTU size. If the RakNet protocol does not match your own, respond with the Incompatible protocol packet.<br><br>
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|Incompatible Protocol]] if it does not support the client's RakNet protocol version.
You should always respond to the first of these packets that you receive with Open Connection Reply 1, containing an MTU size of the amount of padding you received in bytes plus 46.


=== Open Connection Reply 1 ===
=== Open Connection Reply 1 ===
The second packet in the handshake sequence, sent by the server to the client.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 324: Line 287:
  ! Notes
  ! Notes
  |-
  |-
  |rowspan="5"| 0x06
  |rowspan="4"| 0x06
| Magic
  | Magic
  | Magic
| MAGIC
  |  
  |  
  |-
  |-
Line 334: Line 297:
  |-
  |-
  | Use security
  | Use security
  | boolean
  | Boolean
  | If true, a cookie can be specified after to prevent source IP spoofing
  | False for the layout shown here.
|-
| Cookie
| Int
| Only if use security; a cookie to be sent back by the client in Open Connection Request 2
  |-
  |-
  | MTU
  | MTU
  | Unsigned short
  | Unsigned Short
  | see Open Connection Request 1
  | Selected MTU for the connection.
  |}
  |}


=== Open Connection Request 2 ===
=== Open Connection Request 2 ===
The third packet in the handshake sequence, sent by the client to the server.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
  ! Field Name
  ! Field Name
  ! Field Type
  ! Field Type
! Notes
  |-
  |-
  |rowspan="6"| 0x07
  |rowspan="4"| 0x07
| Magic
  | Magic
  | Magic
| MAGIC
|
|-
| Cookie
| Int
| Only present if a cookie was provided by the server in Open Connection Reply 1
  |-
  |-
  | Has security challenge
  | Server Address
  | boolean
  | Address
| Only present if a cookie was provided by the server in Open Connection Reply 1
  |-
  |-
| Server Address
| address
|
|-
  | MTU
  | MTU
  | short
  | Unsigned Short
  |
  |-
|-
  | Client GUID
  | Client GUID
  | Long
  | Long
|
  |}
  |}


=== Open Connection Reply 2 ===
=== Open Connection Reply 2 ===
The fourth packet in the handshake sequence, sent by the server to the client.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 391: Line 340:
  |rowspan="5"| 0x08
  |rowspan="5"| 0x08
  | Magic
  | Magic
  | MAGIC
  | Magic
  |  
  |  
  |-
  |-
Line 399: Line 348:
  |-
  |-
  | Client Address
  | Client Address
  | address
  | Address
  |  
  |  
  |-
  |-
  | MTU
  | MTU
  | short
  | Unsigned Short
  |  
  |  
  |-
  |-
  | Encryption enabled
  | Encryption enabled
  | boolean
  | Boolean
  |  
  | False for the layout shown here.
  |}
  |}


=== Connection Request ===
=== Connection Request ===
The client sends this framed message after Open Connection Reply 2 to continue the RakNet handshake.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
  ! Field Name
  ! Field Name
  ! Field Type
  ! Field Type
! Notes
  |-
  |-
  |rowspan="3"| 0x09
  |rowspan="3"| 0x09
  | GUID
  | GUID
  | Long
  | Long
|
  |-
  |-
  | Time
  | Time
  | Long
  | Long
|
  |-
  |-
  | Use security
  | Use security
  | boolean
  | Boolean
|
  |}
  |}


=== Connection Request Accepted ===
=== Connection Request Accepted ===
The server sends this packet to accept the client's connection request.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 441: Line 392:
  |rowspan="5"| 0x10
  |rowspan="5"| 0x10
  | Client address
  | Client address
  | address
  | Address
  |  
  |  
  |-
  |-
  | System index
  | System index
  | short
  | Unsigned Short
  | Unknown what this does. 0 works as a value.
  | System index assigned by the server.
  |-
  |-
  | Internal IDs
  | Internal addresses
  | 10x address
  | Address array
  | Unknown what these do. 255.255.255.255:19132 for all of them seems to work, any other address will probably work as well.
  | Internal server addresses; the count varies by implementation, commonly 10 or 20.<ref name="accepted-addresses">[https://github.com/Sandertv/go-raknet/blob/master/internal/message/connection_request_accepted.go go-raknet: Connection Request Accepted]</ref>
  |-
  |-
  | Request time
  | Request time
  | Long
  | Long
  |  
  | Timestamp from the corresponding [[#Connection Request|Connection Request]].
  |-
  |-
  | Time
  | Time
  | Long
  | Long
  |  
  | Server acceptance time.
  |}
  |}


=== New Incoming Connection ===
=== New Incoming Connection ===
The client sends this packet to confirm that it received the server's acceptance.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 470: Line 424:
  |rowspan="4"| 0x13
  |rowspan="4"| 0x13
  | Server address
  | Server address
  | address
  | Address
  |  
  |  
  |-
  |-
  | Internal address
  | Internal addresses
  | 20x address
  | Address array
  | Unknown what this is used for.
  | Internal client addresses; the count varies by implementation, commonly 10 or 20.<ref>[https://github.com/Sandertv/go-raknet/blob/master/internal/message/new_incoming_connection.go go-raknet: New Incoming Connection]</ref>
|-
  |-
  |-
  | Incoming Timestamp
  | Ping time
  | Long
  | Long
  |  
  | Server acceptance timestamp echoed by the client.
  |-
  |-
  |-
  | Pong time
| Server Timestamp
  | Long
  | Long
  |  
  | Time at which the client sends this message.
|-
  |}
  |}


=== Disconnect ===
=== Disconnection Notification ===
 
This packet notifies the other peer that the sender is disconnecting.
 
{| class="wikitable"
{| class="wikitable"
! Packet ID
! Packet ID !! Field Name !! Field Type !! Notes
|-
|-
|0x15
| 0x15 || colspan="2" | No payload || Signals that the sender is disconnecting.
|-
|}
|}


=== Incompatible Protocol ===
=== Incompatible Protocol ===
The server sends this packet when it does not support the RakNet protocol version used by the client.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
  ! Field Name
  ! Field Name
  ! Field Type
  ! Field Type
! Notes
  |-
  |-
  |rowspan="3"| 0x19
  |rowspan="3"| 0x19
  | Protocol
  | Protocol
  | byte
  | Byte
|
  |-
  |-
  | Magic
  | Magic
  | MAGIC
  | Magic
|
  |-
  |-
  | Server GUID
  | Server GUID
  | Long
  | Long
|
|-
  |}
  |}


=== Unconnected Ping ===
=== Frame Set Packet ===
{| class="wikitable"
 
! Packet ID
This packet carries one or more frames between connected peers.
! Field Name
! Field Type
! Notes
|-
|rowspan="2"| 0x01, 0x02
| Time
| Long
|
|-
| GUID
| Long
|
|}


=== Frame Set Packet ===
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 543: Line 480:
  ! Notes
  ! Notes
  |-
  |-
  |rowspan="11"| 0x80..0x8d
  |rowspan="11"| 0x80–0x9f
  |colspan="3"| Sequence number
  |colspan="3"| Sequence number
  | uint24le
  | uint24le
  |  
  | Used for building [[#ACK|ACK]] and [[#NACK|NACK]] ranges
  |-
  |-
  |rowspan="10"| Frames
  |rowspan="10"| Frames
  |colspan="2"| Flags
  |colspan="2"| Flags
  | byte
  | Byte
  | Top 3 bits are reliability type, fourth bit is 1 when the frame is fragmented and part of a compound.
  | Top 3 bits give the reliability type, fourth bit is 1 when the frame is fragmented and part of a compound.
  |-
  |-
  |colspan="2"| Length IN BITS
  |colspan="2"| Body bit length
  | unsigned short
  | Unsigned Short
  | Length of the body in bits.
  | Length of this frame's body in bits.
  |-
  |-
  |colspan="2"| Reliable frame index
  |colspan="2"| Reliable frame index
  | uint24le
  | uint24le
  | only if reliable
  | Only if reliable, used for detecting frame level duplication
  |-
  |-
  |colspan="2"| Sequenced frame index
  |colspan="2"| Sequenced frame index
  | uint24le
  | uint24le
  | only if sequenced
  | Only if sequenced, used for discarding out-of-date packets
  |-
  |-
  |rowspan="2"| Order
  |rowspan="2"| Order<br>(if ordered or sequenced)
  | Ordered frame index
  | Ordered frame index
  | uint24le
  | uint24le
  |rowspan="2"| only if ordered, only one channel (0) is used when encryption is enabled
  | Tells the receiver the correct order in which to deliver frames to the application
  |-
  |-
  | Order channel
  | Order channel
  | byte
  | Byte
| Maximum of 32 channels
  |-
  |-
  |rowspan="3"| Fragment
  |rowspan="3"| Fragment<br>(only if fragmented)
  | Compound size
  | Compound size
  | int
  | Unsigned Int
  |rowspan="3"| only if fragmented
  | Number of fragments in the split message.
  |-
  |-
  | Compound ID
  | Compound ID
  | short
  | Unsigned Short
| Identifies which compound this fragment is part of
  |-
  |-
  | Index
  | Index
  | int
  | Unsigned Int
| Zero-based index of this fragment in the split message.
  |-
  |-
  | Body
  | Body
  | ceil(length/8) bytes
  | ceil(length/8) bytes
|
  |}
  |}


The reliability types are as follows:
A frame-set header has bit {{cd|0x80}} set and ACK/NACK bits {{cd|0x60}} clear. The remaining bits are flags, so the header is not a fixed message ID. A frame set can contain multiple frames.<ref name="frames">[https://github.com/Sandertv/go-raknet/blob/master/packet.go go-raknet: Frame encoding]</ref>
 
The reliability values transmitted in the frame header are as follows:


{| class="wikitable"
{| class="wikitable"
Line 594: Line 537:
! style="font-weight: bold;" | Name
! style="font-weight: bold;" | Name
! style="text-align: center; font-weight: bold;" | Reliable
! style="text-align: center; font-weight: bold;" | Reliable
! style="text-align: center; font-weight: bold;" | Sequenced
! style="text-align: center; font-weight: bold;" | Ordered
! style="text-align: center; font-weight: bold;" | Ordered
! style="text-align: center; font-weight: bold;" | Sequenced
|-
|-
| style="text-align: center;" | 0
| style="text-align: center;" | 0
Line 607: Line 550:
| style="text-align: center;" |  
| style="text-align: center;" |  
| style="text-align: center;" | x
| style="text-align: center;" | x
| style="text-align: center;" | x
| style="text-align: center;" |  
|-
|-
| style="text-align: center;" | 2
| style="text-align: center;" | 2
Line 618: Line 561:
| reliable ordered
| reliable ordered
| style="text-align: center;" | x
| style="text-align: center;" | x
| style="text-align: center;" |
| style="text-align: center;" | x
| style="text-align: center;" | x
| style="text-align: center;" |
|-
|-
| style="text-align: center;" | 4
| style="text-align: center;" | 4
| reliable sequenced
| reliable sequenced
| style="text-align: center;" | x
| style="text-align: center;" | x
| style="text-align: center;" | x
|-
| style="text-align: center;" | 5
| unreliable (+ ACK receipt)
| style="text-align: center;" |
| style="text-align: center;" |
| style="text-align: center;" |
|-
| style="text-align: center;" | 6
| reliable (+ ACK receipt)
| style="text-align: center;" | x
| style="text-align: center;" |
| style="text-align: center;" |
|-
| style="text-align: center;" | 7
| reliable ordered (+ ACK receipt)
| style="text-align: center;" | x
| style="text-align: center;" | x
| style="text-align: center;" | x
| style="text-align: center;" | x
Line 646: Line 571:
|}
|}


Sequenced implies ordered.
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.<ref>[https://github.com/facebookarchive/RakNet/blob/master/Source/ReliabilityLayer.cpp RakNet: Reliability layer]</ref>
 
Sequenced delivery discards older packets when a newer packet has arrived. Ordered delivery preserves the order of reliable packets within a channel.


=== Game Packet ===
=== Game Packet ===
This Bedrock-specific message carries a batch of game packets inside a RakNet frame.
{| class="wikitable"
{| class="wikitable"
  ! Packet ID
  ! Packet ID
Line 658: Line 588:
  | Body
  | Body
  | bytes
  | bytes
  | Single packet of the GAME protocol. The packet is usually compressed.
  | In [[Minecraft:Bedrock Edition]], the body contains a batch of game packets. Framing and compression are described in [[Minecraft:Bedrock Edition protocol#Packet format|Bedrock Edition protocol]].
  |}
  |}
Packet definitions are listed at [[Minecraft:Bedrock Edition protocol/Packets]].


=== NACK ===
=== NACK ===
This packet reports [[Minecraft:wikipedia:User_Datagram_Protocol|datagrams]] that were not received so the sender can retransmit them when required.
{| class="wikitable"
{| class="wikitable"
! style="font-weight: bold;" | Packet ID
! style="font-weight: bold;" | Packet ID
Line 670: Line 604:
| rowspan="5" | 0xa0
| rowspan="5" | 0xa0
| colspan="3" | Record count
| colspan="3" | Record count
| short
| Unsigned Short
|  
| Number of records in the packet
|-
|-
| rowspan="4" | Record
| rowspan="4" | Records
| colspan="2" | Single Sequence number?
| colspan="2" | Is Single?
| boolean
| boolean
| False for range, True for no range
| False for range, True for no range
|-
|-
| No Range
| No Range, if <code>is_single == true</code>
| Sequence number
| Sequence number
| uint24le
| uint24le
| rowspan="3" | Number of sequence to not acknowledge
| Datagram sequence number in this record.
|-
|-
| rowspan="2" | Range
| rowspan="2" | Range, if <code>is_single == false</code>
| Start Sequence number
| Start Sequence number
| uint24le
| uint24le
|First datagram sequence number in the inclusive range.
|-
|-
| End Sequence number
| End Sequence number
| uint24le
| uint24le
|Last datagram sequence number in the inclusive range.
|}
|}
A NACK reports frame-set sequence numbers that were not received, prompting retransmission where required.


=== ACK ===
=== ACK ===
This packet acknowledges [[Minecraft:wikipedia:User_Datagram_Protocol|datagrams]] received from the other peer.
{| class="wikitable"
{| class="wikitable"
! style="font-weight: bold;" | Packet ID
! style="font-weight: bold;" | Packet ID
Line 700: Line 640:
| rowspan="5" | 0xc0
| rowspan="5" | 0xc0
| colspan="3" | Record count
| colspan="3" | Record count
| short
| Unsigned Short
|  
| Number of records in the packet
|-
|-
| rowspan="4" | Record
| rowspan="4" | Records
| colspan="2" | Single Sequence number?
| colspan="2" | Is Single?
| boolean
| boolean
| False for range, True for no range
| False for range, True for no range
|-
|-
| No Range
| No Range, if <code>is_single == true</code>
| Sequence number
| Sequence number
| uint24le
| uint24le
| rowspan="3" | Number of sequence to acknowledge
| Datagram sequence number in this record.
|-
|-
| rowspan="2" | Range
| rowspan="2" | Range, if <code>is_single == false</code>
| Start Sequence number
| Start Sequence number
| uint24le
| uint24le
|First datagram sequence number in the inclusive range.
|-
|-
| End Sequence number
| End Sequence number
| uint24le
| uint24le
|Last 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 ==
== References ==
{{MC/Reflist}}
{{reflist}}


== Navigation ==
== Navigation ==
{{MC/Navbox Bedrock Edition}}
{{Navbox Bedrock Edition}}


[[Category:Bedrock Edition]]
[[Category:Bedrock Edition]]
{{MC/License wiki.vg}}

Latest revision as of 11:10, 20 October 2026

Template:Exclusive

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

Minecraft:NetherNet became the default transport for Minecraft:Bedrock Dedicated Server in Minecraft:26.50.<ref>Template:Cite</ref> RakNet is deprecated in Minecraft:26.60, which removes client support for it.<ref>Template:Cite</ref>

Libraries

The following libraries implement RakNet. Supported features and protocol versions vary between implementations.

Name Description Language License
go-raknet RakNet implementation written in Go. Go MIT
RakNet Asynchronous RakNet implementation written in Rust. Rust Apache-2.0
PieRakNet RakNet implementation written in Python. Python GPL-3.0
Cloudburst Network Network components used by CloudburstMC projects. Java Apache-2.0
rak-net Python RakNet implementation originally developed for Podrum. Python GPL-2.0
JRakNet Java implementation of the RakNet protocol. Java MIT
netty-raknet RakNet implementation for Netty. Java MIT
JRakLibPlus RakNet server library based on RakLib and JRakLib. Java LGPL-3.0
RakLib Lightweight PHP RakNet server implementation. PHP GPL-3.0
raknet UDP networking library for Node.js that follows the RakNet protocol. JavaScript MIT
PyRakLib Python port of RakLib that follows the RakNet protocol. Python GPL
rust-raknet RakNet implementation written in Rust. Rust MIT
Baltica Bedrock toolkit that includes a RakNet implementation. TypeScript See repository
RakNet.Py RakNet implementation written in Python. Python GPL-2.0
LavishMC RakNet C++ fork of the original RakNet implementation. C++ BSD
RakNet (original) Original C++ RakNet implementation. C++ BSD-2-Clause

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.<ref>RakNet: BitStream go-raknet: Frame encoding</ref>

Type Size Description
Byte 1 byte Unsigned 8-bit value.
Boolean 1 byte Template:Cd is false; Template:Cd is true.
Short 2 bytes Signed 16-bit integer.
Unsigned Short 2 bytes Unsigned 16-bit integer.
Int 4 bytes Signed 32-bit integer.
Unsigned Int 4 bytes Unsigned 32-bit integer.
Long 8 bytes 64-bit integer. Whether it represents a signed value depends on the field.
uint24le 3 bytes Unsigned 24-bit little-endian integer, used for datagram sequence numbers and frame indices.
String Variable An unsigned 16-bit byte length followed by that many string bytes.
Magic 16 bytes The fixed Template:Cd value used in offline packets.<ref>RakNet: RakPeer.cpp</ref>
Address 7 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.<ref name="address-format">go-raknet: Address encoding</ref>

Handshake sequence

The handshake begins with unconnected UDP packets and continues with connection-control messages carried inside RakNet frames.<ref>RakNet: RakPeer.cpp go-raknet: Connection messages</ref>

  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 Minecraft: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.<ref>RakNet: Message identifiers go-raknet: Frame encoding</ref>

Unconnected Ping

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

Packet ID Field Name Field Type
0x01, 0x02 Time Long
Magic Magic
Client GUID Long

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 Minecraft:Bedrock Edition, that string contains server-list information in a semicolon-delimited format; its fields can vary by game version.

Packet ID Field Name Field Type Notes
0x1c Time Long
Server GUID Long
Magic Magic
Server ID String String Carries server-list information.

Connected Ping

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

Packet ID Field Name Field Type
0x00 Time Long

Connected Pong

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

Packet ID Field Name Field Type
0x03 Ping Time Long
Pong Time Long

Open Connection Request 1

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

Packet ID Field Name Field Type Notes
0x05 Magic Magic
Protocol version Byte RakNet protocol version used by the client; separate from the Bedrock game protocol version.
Padding Zero bytes Zero 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 ID Field Name Field Type Notes
0x06 Magic Magic
Server GUID Long
Use security Boolean False for the layout shown here.
MTU Unsigned Short Selected MTU for the connection.

Open Connection Request 2

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

Packet ID Field Name Field Type
0x07 Magic Magic
Server Address Address
MTU Unsigned Short
Client GUID Long

Open Connection Reply 2

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

Packet ID Field Name Field Type Notes
0x08 Magic Magic
Server GUID Long
Client Address Address
MTU Unsigned Short
Encryption enabled Boolean False for the layout shown here.

Connection Request

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

Packet ID Field Name Field Type
0x09 GUID Long
Time Long
Use security Boolean

Connection Request Accepted

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

Packet ID Field Name Field Type Notes
0x10 Client address Address
System index Unsigned Short System index assigned by the server.
Internal addresses Address array Internal server addresses; the count varies by implementation, commonly 10 or 20.<ref name="accepted-addresses">go-raknet: Connection Request Accepted</ref>
Request time Long Timestamp from the corresponding Connection Request.
Time Long Server acceptance time.

New Incoming Connection

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

Packet ID Field Name Field Type Notes
0x13 Server address Address
Internal addresses Address array Internal client addresses; the count varies by implementation, commonly 10 or 20.<ref>go-raknet: New Incoming Connection</ref>
Ping time Long Server acceptance timestamp echoed by the client.
Pong time Long Time at which the client sends this message.

Disconnection Notification

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

Packet ID Field Name Field Type Notes
0x15 No payload Signals 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 ID Field Name Field Type
0x19 Protocol Byte
Magic Magic
Server GUID Long

Frame Set Packet

This packet carries one or more frames between connected peers.

Packet ID Field Name Field Type Notes
0x80–0x9f Sequence number uint24le Used for building ACK and NACK ranges
Frames Flags Byte Top 3 bits give the reliability type, fourth bit is 1 when the frame is fragmented and part of a compound.
Body bit length Unsigned Short Length of this frame's body in bits.
Reliable frame index uint24le Only if reliable, used for detecting frame level duplication
Sequenced frame index uint24le Only if sequenced, used for discarding out-of-date packets
Order
(if ordered or sequenced)
Ordered frame index uint24le Tells the receiver the correct order in which to deliver frames to the application
Order channel Byte Maximum of 32 channels
Fragment
(only if fragmented)
Compound size Unsigned Int Number of fragments in the split message.
Compound ID Unsigned Short Identifies which compound this fragment is part of
Index Unsigned Int Zero-based index of this fragment in the split message.
Body ceil(length/8) bytes

A frame-set header has bit Template:Cd set and ACK/NACK bits Template:Cd clear. The remaining bits are flags, so the header is not a fixed message ID. A frame set can contain multiple frames.<ref name="frames">go-raknet: Frame encoding</ref>

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

ID Name Reliable Sequenced Ordered
0 unreliable
1 unreliable sequenced x
2 reliable x
3 reliable ordered x x
4 reliable sequenced x x

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.<ref>RakNet: Reliability layer</ref>

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 ID Field Name Field Type Notes
0xfe Body bytes In Minecraft:Bedrock Edition, the body contains a batch of game packets. Framing and compression are described in Bedrock Edition protocol.

Packet definitions are listed at Minecraft:Bedrock Edition protocol/Packets.

NACK

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

Packet ID Field Name Field Type Notes
0xa0 Record count Unsigned Short Number of records in the packet
Records Is Single? boolean False for range, True for no range
No Range, if is_single == true Sequence number uint24le Datagram sequence number in this record.
Range, if is_single == false Start Sequence number uint24le First datagram sequence number in the inclusive range.
End Sequence number uint24le Last 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 ID Field Name Field Type Notes
0xc0 Record count Unsigned Short Number of records in the packet
Records Is Single? boolean False for range, True for no range
No Range, if is_single == true Sequence number uint24le Datagram sequence number in this record.
Range, if is_single == false Start Sequence number uint24le First datagram sequence number in the inclusive range.
End Sequence number uint24le Last 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

Template:Reflist

Navigation

Template:Navbox Bedrock Edition