Skip to main content

Network

Trait Network 

Source
pub trait Network {
    type Addr: Ord;

    // Required methods
    fn net_start(&mut self) -> Result<(), NetworkError>;
    fn net_stop(&mut self) -> Result<(), NetworkError>;
    fn net_local_addr(&self) -> Self::Addr;
    fn net_advertise(&mut self) -> Result<(), NetworkError>;
    fn net_recv(
        &mut self,
    ) -> Result<Option<(Self::Addr, Box<[u8]>)>, NetworkError>;
    fn net_send(
        &mut self,
        addr: Self::Addr,
        data: &[u8],
    ) -> Result<(), NetworkError>;
    fn net_send_status(
        &mut self,
        addr: Self::Addr,
    ) -> Result<SendStatus, NetworkError>;
}

Required Associated Types§

Source

type Addr: Ord

The type representing the network address. Must be unique.

For emulator, it is IP+port. For the physical device, it is MAC address.

Required Methods§

Source

fn net_start(&mut self) -> Result<(), NetworkError>

Start accepting incoming network connections from other peers.

Source

fn net_stop(&mut self) -> Result<(), NetworkError>

Stop accepting incoming network connections from other peers.

Source

fn net_local_addr(&self) -> Self::Addr

Network address of the current device as visible to the other peers.

Used to sort all the peers, including the local one, in the same order on all devices.

Source

fn net_advertise(&mut self) -> Result<(), NetworkError>

Broadcast device presence to all other devices nearby.

Source

fn net_recv(&mut self) -> Result<Option<(Self::Addr, Box<[u8]>)>, NetworkError>

Get a pending message, if any. Non-blocking.

Source

fn net_send( &mut self, addr: Self::Addr, data: &[u8], ) -> Result<(), NetworkError>

Send a raw message to the given device. Non-blocking.

Source

fn net_send_status( &mut self, addr: Self::Addr, ) -> Result<SendStatus, NetworkError>

Send a raw message to the given device. Non-blocking.

Implementors§