MCPcopy Index your code
hub / github.com/b23r0/rust-raknet

github.com/b23r0/rust-raknet @v0.12.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.12.0 ↗ · + Follow
180 symbols 502 edges 12 files 23 documented · 13%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rust-raknet Build Status ChatOnDiscord Crate Crate

RakNet Protocol implementation by Rust.

Raknet is a reliable udp transport protocol that is generally used for communication between game clients and servers, and is used by Minecraft Bedrock Edtion for underlying communication.

Raknet protocol supports various reliability options, and has better transmission performance than TCP in unstable network environments. This project is an incomplete implementation of the protocol by reverse engineering.

Requires >= Tokio 1.x asynchronous runtime support.

Reference : http://www.jenkinssoftware.com/raknet/manual/index.html

This project is not affiliated with Jenkins Software LLC nor RakNet.

Features

  • Async
  • MIT License
  • Pure Rust implementation
  • Fast Retransmission
  • Selective Retransmission (TCP/Full Retransmission)
  • Non-delayed ACK (TCP/Delayed ACK)
  • RTO Not Doubled (TCP/RTO Doubled)
  • Linux/Windows/Mac/BSD support
  • Compatible with Minecraft 1.18.x

Get Started

# Cargo.toml
[dependencies]
rust-raknet = "*"

Documentation : https://docs.rs/rust-raknet/latest/rust_raknet/

Reliability

  • [x] unreliable
  • [x] unreliable sequenced
  • [x] reliable
  • [x] reliable ordered
  • [x] reliable sequenced

Example

//server

async fn serve(){
    let mut listener = RaknetListener::bind("127.0.0.1:19132".parse().unwrap()).await.unwrap();
    listener.listen().await;
    loop{
        let socket = listener.accept().await.unwrap();
        let buf = socket.recv().await.unwrap();
        if buf[0] == 0xfe{
            //do something
        }
    }
    listener.close().await.unwrap();
}

//client

async fn connect(){
    let socket = RaknetSocket::connect("127.0.0.1:19132".parse().unwrap()).await.unwrap();
    socket.send(&[0xfe], Reliability::ReliableOrdered).await.unwrap();
    let buf = socket.recv().await.unwrap();
    if buf[0] == 0xfe{
        //do something
    }
    socket.close().await.unwrap();
}

Benchmark

Use Tcp to compare with this project. Set the server packet loss rate to 50%, the client connects to the server, and the server sends an 800-byte packet every 30ms, a total of 100 times. The client counts the delay time of each received data, and calculates the average time of receiving 100 times. The following results are obtained.

Test code: https://github.com/b23r0/rust-raknet/blob/main/example/test_benchmark/src/main.rs

Result:

image

(June 12, 2022)

In the network environment with high packet loss rate, this project can reduce the delay time by about 50% compared with TCP.

Contribution

Options :

  • Report a BUG
  • Submit an ISSUE about suggestion
  • Submit a improved PR
  • Add an example of using rust-raknet
  • Supplement the documentation about using rust-raknet

Everyone for me, I for everyone.

Core symbols most depended-on inside this repo

send
called by 30
src/socket.rs
insert
called by 28
src/arq.rs
cur_timestamp_millis
called by 24
src/utils.rs
recv
called by 24
src/socket.rs
get_raw_payload
called by 18
src/datatype.rs
close
called by 17
src/socket.rs
read_u16
called by 15
src/datatype.rs
to_u8
called by 14
src/arq.rs

Shape

Method 95
Function 55
Class 26
Enum 4

Languages

Rust100%

Modules by API surface

src/packet.rs48 symbols
src/arq.rs41 symbols
src/datatype.rs30 symbols
src/socket.rs20 symbols
src/server.rs14 symbols
src/lib.rs9 symbols
src/fragment.rs8 symbols
src/utils.rs3 symbols
example/test_benchmark/src/main.rs3 symbols
example/proxy/src/main.rs2 symbols
src/log.rs1 symbols
src/error.rs1 symbols

For agents

$ claude mcp add rust-raknet \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact