Struct rollo::server::SocketTools[][src]

pub struct SocketTools {
    pub socket_addr: SocketAddr,
    pub id: u64,
    // some fields omitted
}
This is supported on crate feature server only.
Expand description

Send packets, latency, SocketTools etc.

Fields

socket_addr: SocketAddrid: u64

Implementations

Send a packet to the session

Examples
use rollo::server::SocketTools;

fn on_message(socket: SocketTools) {
    socket.send(1, None);
}

Send Bytes(Packet) to the session

Examples
use rollo::server::SocketTools;
use rollo::packet::to_bytes;

fn on_message(socket: SocketTools) {
    let bytes = to_bytes(1, None).freeze();
    socket.send_data(bytes);
}

get Latency

Examples
use rollo::server::SocketTools;

fn on_message(socket: SocketTools) {
    let latency = socket.get_latency();
}

Close the session

Examples
use rollo::server::SocketTools;

fn on_message(socket: SocketTools) {
    if socket.close().is_err() {
        println!("Error when closing the session");
    }
}

Close the session with a delay

Examples
use rollo::server::SocketTools;
use std::time::Duration;

fn on_message(socket: SocketTools) {
    if socket.close_with_delay(Duration::from_secs(1)).is_err() {
        println!("Error when closing the session");
    }
}

Is connection close ?

Examples
use rollo::server::SocketTools;

fn on_message(socket: SocketTools) {
    if socket.is_closed() {
    // Do something
    }
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Compare self to key and return true if they are equal.

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.