[−][src]Trait drogue_network::UdpStack
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
Required methods
fn open(
&self,
remote: SocketAddr,
mode: Mode
) -> Result<Self::UdpSocket, Self::Error>
&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>
&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>
&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.