Repository navigation
Quick Start EN
Minimum requirements: Rust 1.85 and Tokio 1.38. The library uses Rust edition 2024. Create examples and run services in a task-specific copy, container or VM with private Cargo caches and build output. Place local services in a private network namespace.
Create a binary project and add these dependencies to Cargo.toml:
[package]
name = "raknet-echo"
version = "0.1.0"
edition = "2024"
[dependencies]
rust-raknet = "1.4.0"
tokio = { version = "1.38", features = ["full"] }These snippets target published 1.4.0. Rust 1.85 is the declared MSRV; tokio = "1.38" is the declared dependency range, not a guarantee that every freshly resolved dependency supports the MSRV. Preserve a compatible lockfile when using older Rust. Send policy, recovery policy and blocking calls are optional.
Save this as src/bin/server.rs:
use rust_raknet::{RaknetListener, Reliability, error::Result};
#[tokio::main]
async fn main() -> Result<()> {
let address = "127.0.0.1:19132".parse().unwrap();
let mut listener = RaknetListener::bind(&address).await?;
listener.listen().await;
loop {
let socket = listener.accept().await?;
tokio::spawn(async move {
while let Ok(message) = socket.recv().await {
if let Err(error) = socket
.send(&message, Reliability::ReliableOrdered)
.await
{
eprintln!("Echo failed: {error}");
break;
}
}
let _ = socket.close().await;
});
}
}bind() creates the UDP socket, listen() starts the listener, and accept() returns a session. Each session runs in its own asynchronous task so the accept loop can keep handling new connections.
Save this as src/bin/client.rs:
use rust_raknet::{RaknetSocket, Reliability, error::Result};
#[tokio::main]
async fn main() -> Result<()> {
let address = "127.0.0.1:19132".parse().unwrap();
let socket = RaknetSocket::connect(&address).await?;
socket.send(&[0xfe, 1, 2, 3], Reliability::ReliableOrdered).await?;
let reply = socket.recv().await?;
println!("Echo: {reply:?}");
socket.close().await
}Run these in separate terminals sharing the same isolated network:
cargo run --bin server
cargo run --bin clientThe client should print Echo: [254, 1, 2, 3]. Both endpoints must share a network namespace. 127.0.0.1 in one container usually does not refer to another container.
The server.rs and client.rs above provide the basic echo example. The repository also includes concurrency, concurrency_benchmark, sharded_echo, interop and bedrock_probe. Check the examples directory for arguments and source.
Ordinary .rs examples use cargo run --example NAME. examples/proxy, examples/bedrock_ping and examples/test_benchmark are separate Cargo projects and use --manifest-path.
English · 简体中文 · GitHub · crates.io 1.4.0 · Reviewed / 核对:2026-10-12 / b909c93
- Overview
- Quick start
- Blocking calls and shared runtimes
- Public API index
- Five reliability modes
- RakNet wire format and recovery
- Message lifecycle and limits
- Bytes and explicit batching
- Send policy
- Recovery policy and tail probes
- Every configuration parameter
- Concurrency and socket tuning
- Errors, deadlines and cancellation
- Congestion and deployment boundaries
- Benchmark results
- Benchmark methodology
- Benchmark reproduction
- Minecraft Bedrock proxy
- Troubleshooting and development
- Release history and upgrading