Module rak_rs::client

source ·
Expand description

A client implementation of RakNet, allowing you to connect to a RakNet server. This module contains the client implementation of RakNet. This module allows you to connect to a RakNet server, and send and receive packets. This is the bare-bones implementation for a RakNet client.

§Getting Started

Connecting to a server is extremely easy with rak-rs, and can be done in a few lines of code. In the following example we connect to my_server.net:19132 and send a small packet, then wait for a response, then close the connection when we’re done.

use rak_rs::client::{Client, DEFAULT_MTU};

#[async_std::main]
async fn main() {
    let version: u8 = 10;
    let mut client = Client::new(version, DEFAULT_MTU);

    if let Err(_) = client.connect("my_server.net:19132").await {
        println!("Failed to connect to server!");
        return;
    }

    println!("Connected to server!");

    client.send_ord(vec![254, 0, 1, 1], Some(1));

    loop {
        let packet = client.recv().await.unwrap();
        println!("Received a packet! {:?}", packet);
        break;
    }

    client.close().await;
}

Modules§

Structs§

  • This is the client implementation of RakNet. This struct includes a few designated methods for sending and receiving packets.

Constants§