Module rak_rs::connection

source ·
Expand description

The connection implementation of RakNet, allowing you to send and receive packets. This is barebones, and you should use the client or server implementations instead, this is mainly used internally. This module contains the logic to handle a connection or “peer” to the server. This is used internally by the server, and is not intended to be used by the end user outside of the server.

This module contains the following:

  • Connection: The connection struct, which is used to hold the connection state.
  • ConnectionState: The connection state enum, which is used to hold the state of the connection.
  • ConnectionMeta: The connection meta struct, which is used to hold the meta information of the connection.

This module also contains the following submodules:

  • controller: The controller submodule, which is used to handle relability of the connection.
  • queue: The queue submodule, which is used to handle the connection queues.
  • state: The state submodule, which is used to handle the connection state.

§Example

This is a snippet of code you would use after you’ve accepted a connection from the server with Listener::accept().

use rakrs::connection::Connection;

async fn handle(mut conn: Connection) {
    loop {
        // get a packet sent from the client
        if let Ok(pk) = conn.recv().await {
            println!("Got a connection packet {:?} ", pk);
        }

        if !conn.state.lock().await.unwrap().is_available() {
            conn.disconnect("Client disconnected.", false);
            println!("Client disconnected!");
            break;
        }
    }
}

Modules§

Structs§

  • The connection struct contains the logic for a connection to the server. The following methods are the most important: