Trait Socket

Source
pub trait Socket {
    // Required methods
    fn recv_from(&mut self, buffer: &mut [u8]) -> Result<(usize, SocketAddr)>;
    fn local_addr(&self) -> SocketAddr;
    fn send_to(&mut self, buffer: &[u8], target: SocketAddr) -> Result<()>;
}
Expand description

A generic trait over a socket. This is automatically implemented for UdpSocket but can be implemented for your own connector as well.

Required Methods§

Source

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

Receive data from any remote, returning the amount of bytes read, and the SocketAddr that the data was received from

Source

fn local_addr(&self) -> SocketAddr

The local SocketAddr we’re listening on

Source

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

Send data to the given SocketAddr

Implementations on Foreign Types§

Source§

impl Socket for UdpSocket

Source§

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

Source§

fn local_addr(&self) -> SocketAddr

Source§

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

Implementors§