Struct cobalt::Client [] [src]

pub struct Client<S: Socket, R: RateLimiter, M: PacketModifier> { /* fields omitted */ }

Implementation of a low latency socket client.

Basic Usage

use cobalt::{
    BinaryRateLimiter, Client, Config, NoopPacketModifier, MessageKind, UdpSocket
};

// Create a new client that communicates over a udp socket
let mut client = Client::<UdpSocket, BinaryRateLimiter, NoopPacketModifier>::new(Config::default());

// Initiate a connection to the server
client.connect("127.0.0.1:1234").expect("Failed to bind to socket");

// loop {

    // Fetch connection events
    while let Ok(event) = client.receive() {
        // Handle events (e.g. Connection, Messages, etc.)
    }

    // Schedule a message to the send to the server
    if let Ok(connection) = client.connection() {
        connection.send(MessageKind::Instant, b"Ping".to_vec());
    }

    // Send all outgoing messages.
    //
    // Also auto delay the current thread to achieve the configured tick rate.
    client.send(true);

// }

// Disconnect the client, closing its connection and unbinding its socket
client.disconnect();

Methods

impl<S: Socket, R: RateLimiter, M: PacketModifier> Client<S, R, M>
[src]

Creates a new client with the given configuration.

Returns the number of bytes sent over the last second.

Returns the number of bytes received over the last second.

Returns the address of the server the client is currently connected to.

Returns the local address that the client is sending from.

Returns a mutable reference to underlying connection to the server.

Returns a mutable reference to the client's underlying socket.

Returns the client's current configuration.

Overrides the client's current configuration.

Establishes a connection with the server at the specified address.

Receives the next incoming message from the client's underlying connection.

Sends all queued messages over the client's underlying connection.

If auto_tick is specified as true this method will block the current thread for the amount of time which is required to limit the number of calls per second (when called inside a loop) to the client's configured send_rate.

Resets the client, clearing all pending events and dropping any connection to the server, returning it into the Connecting state.

This can be used to re-try a connection attempt if a previous one has failed.

Drops the client's connection to the server, freeing the socket and clearing any state.

Trait Implementations

impl<S: Debug + Socket, R: Debug + RateLimiter, M: Debug + PacketModifier> Debug for Client<S, R, M>
[src]

Formats the value using the given formatter.