RakNet Protocol implementation by Rust.

Overview

rust-raknet Build Status ChatOnDiscord Crate Crate

RakNet Protocol implementation by Rust.

Raknet is a reliable udp transport protocol that is often used for communication between game clients and servers. This project is an incomplete implementation of the protocol.

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
  • 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 = "0.5.0"

Reliability

  • unreliable
  • unreliable sequenced
  • reliable
  • reliable ordered
  • 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 mut socket = listener.accept().await.unwrap();
        let buf = socket.recv().await.unwrap();
        if buf[0] == 0xfe{
            //do something
        }
        socket.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();
}

Contribution

If you want to develop with me, you can contact me via discord or email.

You might also like...
A multi-protocol network relay

A multi-protocol network relay

The Graph is a protocol for building decentralized applications (dApps) quickly on Ethereum and IPFS using GraphQL.

Graph Node The Graph is a protocol for building decentralized applications (dApps) quickly on Ethereum and IPFS using GraphQL. Graph Node is an open s

🤖 Autonomous Twitter bot that posts analytics of the APYs available on the Solend Protocol.
🤖 Autonomous Twitter bot that posts analytics of the APYs available on the Solend Protocol.

Solend APY Twitter Bot Solana Ignition Hackathon 2021 View Demo · Report Bug · Request Feature Table of Contents About The Project Motivation Challeng

Yet Another File Transfer Protocol.

yaftp Yet Another File Transfer Protocol. Build & Run $ cargo build --release Features C2C Lightweight Per something per session High performence Res

An End-to-End Privacy Computing Protocol on Layer 2

Eigen Network Eigen Network is an end-to-end privacy computation network for a better digital economy based on hybrid privacy computation protocols an

Shade Protocol is an array of connected privacy-preserving dApps built on Secret Network

Shade Protocol Core Contracts Contract Reference Description mint doc Handles asset burning and silk minting oracle doc Handles asset price queries tr

IDP2P is a peer-to-peer identity protocol which enables a controller to create, manage and share its own proofs as well as did documents
IDP2P is a peer-to-peer identity protocol which enables a controller to create, manage and share its own proofs as well as did documents

IDP2P Experimental, inspired by ipfs, did:peer and keri Background See also (related topics): Decentralized Identifiers (DIDs) Verifiable Credentials

UDP proxy with Proxy Protocol and mmproxy support
UDP proxy with Proxy Protocol and mmproxy support

udppp UDP proxy with Proxy Protocol and mmproxy support. Features Async Support Proxy Protocol V2 SOCKET preserve client IP addresses in L7 proxies(mm

Off-chain services for Gnosis Protocol v2

Cow Protocol Services This repository contains backend code for Cow Protocol Services written in Rust. Order Book The orderbook crate provides the htt

Comments
  • Couldn't connect to server with `unwrap()` called on `Result` on a `Err` value

    Couldn't connect to server with `unwrap()` called on `Result` on a `Err` value

    Created simple packet listener, my code:

    #[tokio::main]
    async fn main() {
        tracing_subscriber::fmt::init();
        let mut socket = rust_raknet::RaknetListener::bind("0.0.0.0:19132".parse().unwrap()).await.unwrap();
        socket.listen().await;
    
        while let Ok(mut s) = socket.accept().await {
            tracing::info!("Accepted connection from {:?}", s.local_addr());
    
            let mut connection = rust_raknet::RaknetSocket::connect(&"51.210.143.233:19132".parse().unwrap()).await.unwrap();
            loop {
                if let Ok(buf) = s.recv().await {
                    tracing::info!("FROM CLIENT: {:?}", &buf);
                    connection.send(buf.as_slice(), Reliability::Reliable).await;
                }
    
                if let Ok(buf) = connection.recv().await {
                    tracing::info!("FROM SERVER: {:?}", &buf);
                    s.send(buf.as_slice(), Reliability::Reliable).await;
                }
            }
        }
    }
    

    Error:

    thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: ReadPacketBufferError', C:\Users\dolabaeb\.cargo\registry\src\github.com-1ecc6299db9ec823\rust-raknet-0.3.1\src\socket.rs:357:137
    

    On line https://github.com/b23r0/rust-raknet/blob/main/src/socket.rs#L371

    opened by feelingnothing 10
  • Error with example proxy

    Error with example proxy

    Cloning library directly from master branch, building proxy.exe with --release on Windows 10 21H2 (19044.1645) and connecting to it through PC version Minecraft 1.18.12 and getting this error:

    thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: ReadPacketBufferError', C:\Users\dolabaeb\CLionProjects\rust-raknet\src\socket.rs:371:137
    stack backtrace:
       0:     0x7ff7082c2fff - std::backtrace_rs::backtrace::dbghelp::trace
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:98
       1:     0x7ff7082c2fff - std::backtrace_rs::backtrace::trace_unsynchronized
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
       2:     0x7ff7082c2fff - std::sys_common::backtrace::_print_fmt
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:67
       3:     0x7ff7082c2fff - std::sys_common::backtrace::_print::impl$0::fmt
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:46
       4:     0x7ff7082d5c2a - core::fmt::write
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\fmt\mod.rs:1168
       5:     0x7ff7082bccb8 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\io\mod.rs:1660
       6:     0x7ff7082c5b5b - std::sys_common::backtrace::_print
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:49
       7:     0x7ff7082c5b5b - std::sys_common::backtrace::print
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:36
       8:     0x7ff7082c5b5b - std::panicking::default_hook::closure$1
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:211
       9:     0x7ff7082c5654 - std::panicking::default_hook
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:228
      10:     0x7ff7082c605c - std::panicking::rust_panic_with_hook
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:606
      11:     0x7ff7082c5f1b - std::panicking::begin_panic_handler::closure$0
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:502
      12:     0x7ff7082c3947 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure$0,never$>
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:139
      13:     0x7ff7082c5c19 - std::panicking::begin_panic_handler
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:498
      14:     0x7ff7082e0520 - core::panicking::panic_fmt
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\panicking.rs:116
      15:     0x7ff7082e05c3 - core::result::unwrap_failed
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\result.rs:1690
      16:     0x7ff70827bf58 - rust_raknet::socket::RaknetSocket::start_receiver::{{closure}}::hdf180a56c8e969e1
      17:     0x7ff70826bd5a - std::panicking::try::hc206c013b6ddaf57
      18:     0x7ff7082713c8 - tokio::runtime::task::harness::Harness<T,S>::complete::hdd4b53e814e17a2e
      19:     0x7ff70826f180 - tokio::runtime::task::harness::Harness<T,S>::poll::h4b79a9f0313f8bda
      20:     0x7ff7082899e7 - std::thread::local::LocalKey<T>::with::hee90645ce63d04a6
      21:     0x7ff7082a7867 - tokio::runtime::thread_pool::worker::Context::run::hf532ea944e9ceb7b
      22:     0x7ff7082a659f - tokio::runtime::thread_pool::worker::Context::run::hf532ea944e9ceb7b
      23:     0x7ff70828f878 - tokio::macros::scoped_tls::ScopedKey<T>::set::h9c078d3da8ad3cf1
      24:     0x7ff7082a5f6a - tokio::runtime::thread_pool::worker::run::h7190bbc6b2ab57df
      25:     0x7ff70828a565 - tokio::runtime::task::core::CoreStage<T>::poll::h8158559ae3fc7af7
      26:     0x7ff708286616 - std::panicking::try::h285da934742423c5
      27:     0x7ff70829df00 - tokio::runtime::task::harness::Harness<T,S>::poll::he531c6aa5d8b0e33
      28:     0x7ff708299d7c - tokio::runtime::blocking::pool::Inner::run::hc60e1a36e26a7d78
      29:     0x7ff70829c7e5 - std::sys_common::backtrace::__rust_begin_short_backtrace::h471c0fb8d6991f35
      30:     0x7ff708288ca3 - <tokio::io::driver::scheduled_io::Readiness as core::ops::drop::Drop>::drop::h9c7660bf59f3dba4
      31:     0x7ff7082c9b5c - alloc::boxed::impl$44::call_once
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\alloc\src\boxed.rs:1854
      32:     0x7ff7082c9b5c - alloc::boxed::impl$44::call_once
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\alloc\src\boxed.rs:1854
      33:     0x7ff7082c9b5c - std::sys::windows::thread::impl$0::new::thread_start
                                   at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys\windows\thread.rs:58
      34:     0x7ffe55f57034 - BaseThreadInitThunk
      35:     0x7ffe56522651 - RtlUserThreadStart
    

    proxy.exe -l 0.0.0.0:19132 -r 146.59.254.235:19132 IP address is Europe HiveMC server

    opened by feelingnothing 3
  • Support customizable protocol version

    Support customizable protocol version

    In order to be compatible with minecraft, the raknet protocol version has to be configurable. It changed in various minecraft versions (without changes to raknet level). In 1.19.30 the latest raknet version is 11.

    https://github.com/PrismarineJS/bedrock-protocol/blob/f88c8d0bc4ed252ad24ec3f9ad25da603dbc4db3/src/rak.js#L34

    opened by extremeheat 2
Releases(v0.12.0)
Owner
b23r0
Life was like a box of chocolates
b23r0
Rustus - TUS protocol implementation in Rust.

Rustus Tus protocol implementation written in Rust. Features This implementation has several features to make usage as simple as possible. Rustus is r

Pavel Kirilin 74 Jan 1, 2023
Rust implementation of TCP + UDP Proxy Protocol (aka. MMProxy)

mmproxy-rs A Rust implementation of MMProxy! ?? Rationale Many previous implementations only support PROXY Protocol for either TCP or UDP, whereas thi

Saikō Technology 3 Dec 29, 2022
🥧 Savoury implementation of the QUIC transport protocol and HTTP/3

quiche is an implementation of the QUIC transport protocol and HTTP/3 as specified by the IETF. It provides a low level API for processing QUIC packet

Cloudflare 7.1k Jan 8, 2023
A proof of concept implementation of RTSP over Dahua P2P protocol.

RTSP Streaming with Dahua P2P Protocol Implementation This is a proof of concept implementation of RTSP over Dahua P2P protocol. It works with Dahua a

null 6 Dec 21, 2023
Easy protocol definitions in Rust

protocol Documentation Easy protocol definitions in Rust. This crate adds a custom derive that can be added to types, allowing structured data to be s

Dylan McKay 157 Dec 30, 2022
A Constrained Application Protocol(CoAP) library implemented in Rust.

coap-rs A fast and stable Constrained Application Protocol(CoAP) library implemented in Rust. Features: CoAP core protocol RFC 7252 CoAP Observe optio

Covertness 170 Dec 19, 2022
A Rust library for parsing the SOME/IP network protocol (without payload interpretation).

someip_parse A Rust library for parsing the SOME/IP network protocol (without payload interpretation). Usage Add the following to your Cargo.toml: [de

Julian Schmid 18 Oct 31, 2022
Peer-to-peer communications library for Rust based on QUIC protocol

qp2p Crate Documentation MaidSafe website SAFE Dev Forum SAFE Network Forum Overview This library provides an API to simplify common tasks when creati

MaidSafe 337 Dec 14, 2022
A simple tool in Rust to split urls in their protocol, host, port, path and query parts.

rexturl A simple tool to split urls in their protocol, host, port, path and query parts. Install cargo install rexturl or clone the source code and r

Volker Schwaberow 3 Oct 22, 2022
🤖 brwrs is a new protocol running over TCP/IP that is intended to be a suitable candidate for terminal-only servers

brwrs is a new protocol running over TCP/IP that is intended to be a suitable candidate for terminal-only servers (plain text data). That is, although it can be accessed from a browser, brwrs will not correctly interpret the browser's GET request.

daCoUSB 3 Jul 30, 2021