NetrexMC / RakNet

RakNet implementation in Rust
Apache License 2.0
44 stars 12 forks source link

[Feature] RakNet Client Peer #40

Closed john-bv closed 1 year ago

john-bv commented 1 year ago

This issue is a followup for #39

The RFC Allows you to open a RakNet Peer Client to connect to other RakNet instances. This RFC contains the following functions:

Example:

use rakrs::client::Client;

async fn connect(address: &'static str) -> Result<(), std::error::Error> {
    let mut conn = Client::new(&address, 10);
    conn.open();

    loop {
        let buf = conn.recv().await?;
        // Send a packet on ordered channel
        conn.send_ord(&[buf], 0);
        // Send a packet sequenced 
        conn.send_seq(&[buf], 0);
        // Send packet reliably (not ord, use send_ord for that)
        conn.send(&[buf], Reliability::Reliable);
    }

    // flush ack and nack forcefully.
    conn.flush_ack();
    conn.close().await?;
}