Trait Transceiver

Source
pub trait Transceiver {
    type IntoError: Into<Error>;

    // Required methods
    fn addr(&self) -> SocketAddr;
    fn recv(
        &self,
        buf: &mut [u8],
    ) -> Result<Option<(usize, SocketAddr)>, Self::IntoError>;
    fn send(
        &self,
        buf: &[u8],
        addr: SocketAddr,
    ) -> Result<usize, Self::IntoError>;
}
Expand description

A trait for sending and receiving data.

Both the server and client use a statically dispatched generic type T: Transceiver to send and receive data, which allows you to use any type that implements this trait as your network socket for a netcode server or client.

See NetcodeSocket for an example implementation. This is also the default implementation used by the server and client.

Required Associated Types§

Required Methods§

Source

fn addr(&self) -> SocketAddr

Returns the local address of the socket (i.e. the address it is bound to).

Mostly used for generating and validating ConnectTokens.

Source

fn recv( &self, buf: &mut [u8], ) -> Result<Option<(usize, SocketAddr)>, Self::IntoError>

Receives a packet from the socket, if one is available.

Should NOT block if no packet is available.

Source

fn send(&self, buf: &[u8], addr: SocketAddr) -> Result<usize, Self::IntoError>

Sends a packet to the specified address.

Should NOT block if the packet cannot be sent.

Implementors§