[][src]Trait drogue_network::UdpStack

pub trait UdpStack {
    type UdpSocket;
    type Error: Debug;
    fn open(
        &self,
        remote: SocketAddr,
        mode: Mode
    ) -> Result<Self::UdpSocket, Self::Error>;
fn write(
        &self,
        socket: &mut Self::UdpSocket,
        buffer: &[u8]
    ) -> Result<(), Self::Error>;
fn read(
        &self,
        socket: &mut Self::UdpSocket,
        buffer: &mut [u8]
    ) -> Result<usize, Self::Error>;
fn close(&self, socket: Self::UdpSocket) -> Result<(), Self::Error>; }

This trait is implemented by UDP/IP stacks. You could, for example, have an implementation which knows how to send AT commands to an ESP8266 WiFi module. You could have another implemenation which knows how to driver the Rust Standard Library's std::net module. Given this trait, you can how write a portable CoAP client which can work with either implementation.

Associated Types

type UdpSocket

The type returned when we create a new UDP socket

type Error: Debug

The type returned when we have an error

Loading content...

Required methods

fn open(
    &self,
    remote: SocketAddr,
    mode: Mode
) -> Result<Self::UdpSocket, Self::Error>

Open a new UDP socket to the given address and port. UDP is connectionless, so unlike TcpStack no connect() is required.

fn write(
    &self,
    socket: &mut Self::UdpSocket,
    buffer: &[u8]
) -> Result<(), Self::Error>

Send a datagram to the remote host.

fn read(
    &self,
    socket: &mut Self::UdpSocket,
    buffer: &mut [u8]
) -> Result<usize, Self::Error>

Read a datagram the remote host has sent to us. Returns Ok(n), which means a datagram of size n has been received and it has been placed in &buffer[0..n], or an error.

fn close(&self, socket: Self::UdpSocket) -> Result<(), Self::Error>

Close an existing UDP socket.

Loading content...

Implementors

Loading content...