Struct cobalt::shared::Connection [] [src]

pub struct Connection {
    // some fields omitted
}

Implementation of reliable UDP based messaging protocol.

Methods

impl Connection
[src]

fn new(config: Config) -> Connection

Creates a new Virtual Connection over the given SocketAddr.

fn id_from_packet(config: &Config, packet: &[u8]) -> Option<ConnectionID>

Extracts a connection id from a valid packet header.

fn is_open(&self) -> bool

Returns whether the connection is currently accepting any incoming packets.

fn is_congested(&self) -> bool

Return whether the connection is currently congested and should be sending less data.

fn get_id(&self) -> ConnectionID

Returns the id of the connection.

fn get_state(&self) -> ConnectionState

Returns the current state of the connection.

fn get_rtt(&self) -> u32

Returns the average roundtrip time for the connection.

fn get_packet_loss(&self) -> f32

Returns the percent of packets that were sent and never acknowledged over the total number of packets that have been send across the connection.

fn write(&mut self, data: &[u8])

Appends to the data that is going to be send with the next outgoing packet.

The number of bytes that will actually be received by the remote end of the connectio is limited by the remote configuration value of cobalt::shared::Config.packet_max_size.

fn read(&mut self) -> &[u8]

Returns the data contained by the last received packet.

This will return at most cobalt::shared::Config.packet_max_size bytes.

fn receive<T>(&mut self, packet: Vec<u8>, owner: &mut T, handler: &mut Handler<T>)

Receives a incoming UDP packet.

fn send<T>(&mut self, socket: &mut Socket, address: &SocketAddr, owner: &mut T, handler: &mut Handler<T>)

Creates a new outgoing UDP packet.

fn reset(&mut self)

Resets the connection for re-use with another address.

fn close(&mut self)

Closes the connection, no further packets will be received or send.