renet2_netcode

Trait ClientSocket

Source
pub trait ClientSocket:
    Debug
    + Send
    + Sync
    + 'static {
    // Required methods
    fn is_encrypted(&self) -> bool;
    fn is_reliable(&self) -> bool;
    fn addr(&self) -> Result<SocketAddr>;
    fn is_closed(&mut self) -> bool;
    fn close(&mut self);
    fn preupdate(&mut self);
    fn try_recv(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr)>;
    fn postupdate(&mut self);
    fn send(
        &mut self,
        addr: SocketAddr,
        packet: &[u8],
    ) -> Result<(), NetcodeTransportError>;
}
Expand description

Unreliable data source for use in NetcodeClientTransport.

See ServerSocket also.

Required Methods§

Source

fn is_encrypted(&self) -> bool

Gets the encryption behavior of the socket.

If the socket internally encrypts packets before sending them, then this should return true. In that case, renetcode will not pre-encrypt packets before Self::send is called.

Should match the encryption policy of the server socket you will connect to.

Source

fn is_reliable(&self) -> bool

Gets the reliability of the socket.

If this is true, then RenetClient will ‘downgrade’ all channels to SendType::Unreliable so there is not a redundant reliability layer.

Should match the reliability of the server socket you will connect to.

Source

fn addr(&self) -> Result<SocketAddr>

Gets the data source’s SocketAddr.

Returns an error if there is no meaningful address. Server sockets should always have an address.

Source

fn is_closed(&mut self) -> bool

Checks if the data source is closed.

Source

fn close(&mut self)

Closes the data source.

This should disconnect any remote connections that are being tracked.

Source

fn preupdate(&mut self)

Handles data-source-specific logic that must run before receiving packets.

Source

fn try_recv(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr)>

Tries to receive the next packet sent to this data source.

Returns the number of bytes written to the buffer, and the source address of the bytes.

Should return std::io::ErrorKind::WouldBlock when no packets are available.

Source

fn postupdate(&mut self)

Handles data-source-specific logic that must run after sending packets.

Source

fn send( &mut self, addr: SocketAddr, packet: &[u8], ) -> Result<(), NetcodeTransportError>

Sends a packet to the designated address.

Should return std::io::ErrorKind::ConnectionAborted if the destination’s connection was closed internally.

Implementors§