[][src]Trait ublox_cellular::prelude::UdpClient

pub trait UdpClient {
    type UdpSocket;
    type Error: Debug;
    pub fn socket(&self) -> Result<Self::UdpSocket, Self::Error>;
pub fn connect(
        &self,
        socket: &mut Self::UdpSocket,
        remote: SocketAddr
    ) -> Result<(), Self::Error>;
pub fn send(
        &self,
        socket: &mut Self::UdpSocket,
        buffer: &[u8]
    ) -> Result<(), Error<Self::Error>>;
pub fn receive(
        &self,
        socket: &mut Self::UdpSocket,
        buffer: &mut [u8]
    ) -> Result<(usize, SocketAddr), Error<Self::Error>>;
pub 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 implementation 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[src]

The type returned when we create a new UDP socket

type Error: Debug[src]

The type returned when we have an error

Loading content...

Required methods

pub fn socket(&self) -> Result<Self::UdpSocket, Self::Error>[src]

Allocate a socket for further use.

pub fn connect(
    &self,
    socket: &mut Self::UdpSocket,
    remote: SocketAddr
) -> Result<(), Self::Error>
[src]

Connect a UDP socket with a peer using a dynamically selected port.

Selects a port number automatically and initializes for read/writing.

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

Send a datagram to the remote host.

The remote host used is either the one specified in UdpStack::connect or the last one used in UdpServerStack::write_to.

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

Read a datagram the remote host has sent to us.

Returns Ok((n, remote)), which means a datagram of size n has been received from remote and been placed in &buffer[0..n], or an error. If a packet has not been received when called, then nb::Error::WouldBlock should be returned.

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

Close an existing UDP socket.

Loading content...

Implementors

Loading content...