A high-performance, modern .NET implementation of the RakNet protocol.
RaknetCS is a performance-oriented, modernized C# implementation of the RakNet protocol. Designed for the high demands of game networking (particularly Minecraft Bedrock Edition), it provides a robust, reliable UDP transport layer with advanced packet handling and session management.
- ✅ Modern Architecture: Built for .NET 9.0+.
- ✅ Reliability Layers: Supports Unreliable, Reliable, and Ordered packet delivery.
- ✅ High Performance: Asynchronous socket operations for minimum latency.
- ✅ Clean API: Intuitive classes for both Listeners (Servers) and Clients.
- ✅ Packet Attribute System: Easy packet registration and dispatching.
- ✅ Fragmentation & Reassembly: Automatically handles large data packets.
Clone the repository and build the project:
git clone https://github.com/BedrockSharp/raknet-cs.git
cd raknet-cs
dotnet buildTo see the project in action and see how it looks in the Minecraft server list:
# From the root directory
dotnet run --project src/RaknetCS.ExampleThis will start a server on port 19132. Open Minecraft Bedrock, go to the Friends tab, and you should see the "RaknetCS Demo Server" under Local Games.
using System.Net;
using RaknetCS.Network;
var listener = new RaknetListener(new IPEndPoint(IPAddress.Any, 19132));
listener.Motd = "MCPE;My Awesome Server;..."; // Set your custom MOTD
listener.SessionConnected += (session) => {
Console.WriteLine($"New session from: {session.PeerEndPoint}");
};
listener.BeginListener();using System.Net;
using RaknetCS.Network;
var client = new RaknetClient();
client.SessionEstablished += (session) => {
Console.WriteLine("Connected to server!");
};
client.BeginConnection(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 19132));Use the attribute-based system to register your packets effortlessly:
[RegisterPacketID(0xFE)]
public class MyCustomPacket : Packet {
public string Message;
public MyCustomPacket(byte[] buffer) : base(buffer) {}
protected override void Serialize(RaknetWriter stream) {
stream.WriteString(Message);
}
protected override void Deserialize(RaknetReader stream) {
Message = stream.ReadString();
}
}Contributions are what make the open-source community such an amazing place!
- Fork the project.
- Create your Feature Branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the Branch (
git push origin feature/AmazingFeature). - Open a Pull Request.
Please see CONTRIBUTING.md for details.
Distributed under the MIT License. See LICENSE for more information.
Maintained with ❤️ by the BedrockSharp team.