Crate udpsocket2

Source
Expand description

A more ergonomic Tokio-enabled UDP socket.

In particular, attention is paid to the fact that a UDP socket can both send and receive datagrams, and that a practical consumer would like to be able to do both of these things, interleaved on the same socket, with non-blocking I/O.

See the UdpSocket struct documentation for more details.

§Examples

let socket = UdpSocket::bind("127.0.0.1:34254")?;

tokio::spawn(
    socket.incoming()
        .for_each(|datagram| { println!("{:?}", datagram); Ok(()) })
        .map_err(|_| ())
);

tokio::spawn(
    socket.send_to(&[0xde, 0xad, 0xbe, 0xef], "127.0.0.1:34254")?
        .map_err(|_| ())
);

Modules§

incoming
send_to

Structs§

UdpDatagram
An individual UDP datagram, either having been received or to be sent over a UDP socket.
UdpSocket
A UDP socket, using non-blocking I/O.