Crates.io | rust-raknet |
lib.rs | rust-raknet |
version | 0.12.0 |
source | src |
created_at | 2022-03-28 09:49:52.707064 |
updated_at | 2022-10-04 15:17:18.802289 |
description | RakNet Protocol implementation by Rust. |
homepage | |
repository | https://github.com/b23r0/rust-raknet |
max_upload_size | |
id | 557706 |
size | 228,796 |
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.
# Cargo.toml
[dependencies]
rust-raknet = "*"
Documentation : https://docs.rs/rust-raknet/latest/rust_raknet/
//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();
}
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:
(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.
Options :
Everyone for me, I for everyone.