Struct bitflags::__core::net::UdpSocket [] [src]

pub struct UdpSocket(_);
1.0.0
[]

A User Datagram Protocol socket.

This is an implementation of a bound UDP socket. This supports both IPv4 and IPv6 addresses, and there is no corresponding notion of a server because UDP is a datagram protocol.

Examples

use std::net::UdpSocket;

{
    let mut socket = try!(UdpSocket::bind("127.0.0.1:34254"));

    // read from the socket
    let mut buf = [0; 10];
    let (amt, src) = try!(socket.recv_from(&mut buf));

    // send a reply to the socket we received data from
    let buf = &mut buf[..amt];
    buf.reverse();
    try!(socket.send_to(buf, &src));
} // the socket is closed here