Yet another project rewritten in Rust.
Stream/Sink/Futurebased async API.- Low level API but easy to use.
- RakNet features:
- Support
Unreliable,ReliableandReliableOrderedpackets. - Support multiple order channels.
- Support
ACK/NACKmechanism.
- Support
- Full tracing powered by minitrace-rust.
- You can track a packet's span during deduplication, fragmentation, ...
Ordered by priority
- Add sliding window congestion control
- Documentation
- More fuzz testing
- Bulk benchmark
- Optimize performance for single thread runtime (IO without Send)
- Robust client implementation
- Use stable rust toolchain (
I like nightly)
See examples for basic usage.
IO is a hidden type that implements the traits Stream and Sink.
Keep polling incoming because it also serves as the router to every IOs.
Apply Sink::poll_flush to IO will trigger to flush all pending packets, ACK/NACK, and stale packets.
Apply Sink::poll_close to IO will ensure that all data is received by the peer before returning (i.e It may keep resending infinitely.).
Notice: All calculations are lazy. You need to decide how long to flush once, and how long to wait when closing before considering the peer is disconnected.
use bytes::Bytes;
use futures::{SinkExt, StreamExt};
use raknet_rs::server::{self, MakeIncoming};
let socket = tokio::net::UdpSocket::bind("127.0.0.1:0").await?;
let config = server::Config::new()
.send_buf_cap(1024)
.sever_guid(114514)
.advertisement(&b"Hello, I am server"[..])
...
let mut incoming = socket.make_incoming(config);
let mut io = incoming.next().await.unwrap();
let data: Bytes = io.next().await.unwrap();
io.send(data).await.unwrap();The current version of the client only has the most basic handshake implementation, and it is not recommended to use it directly.
use bytes::Bytes;
use futures::{SinkExt, StreamExt};
use raknet_rs::client::{self, ConnectTo};
let socket = tokio::net::UdpSocket::bind("0.0.0.0:0").await?;
let config = client::Config::new()
.send_buf_cap(1024)
.client_guid(1919810)
...
let mut conn = socket.connect_to(<addr>, config).await?;
conn.send(Bytes::from_static(b"Hello, Anyone there?"))
.await?;
let res: Bytes = conn.next().await.unwrap();