net::udp
Index
Types
type connect_option = net::sockflag;
type listen_option = (reuseport | reuseaddr | portassignment | net::sockflag);
type portassignment = *u16;
type reuseaddr = void;
type reuseport = void;
Functions
fn connect(dest: ip::addr, port: u16, options: connect_option...) (net::socket | net::error);
fn listen(addr: ip::addr, port: u16, options: listen_option...) (net::socket | net::error);
fn recv(sock: net::socket, buf: []u8) (size | net::error);
fn recvfrom(sock: net::socket, buf: []u8, src: nullable *ip::addr, port: nullable *u16) (size | net::error);
fn send(sock: net::socket, buf: []u8) (size | net::error);
fn sendto(sock: net::socket, buf: []u8, dest: ip::addr, port: u16) (size | net::error);
Types
type connect_option
type connect_option = net::sockflag;
Options for connect.
type listen_option
type listen_option = (reuseport | reuseaddr | portassignment | net::sockflag);
Options available for listen.
type portassignment
type portassignment = *u16;
To have the system select an arbitrary unused port for listen, set port to zero. To retrieve the assigned port, provide this as one of the options and the addressed u16 will be filled in with the port.
type reuseaddr
type reuseaddr = void;
Enables address re-use for a UDP listener.
type reuseport
type reuseport = void;
Enables port re-use for a UDP listener.
Functions
fn connect
fn connect(dest: ip::addr, port: u16, options: connect_option...) (net::socket | net::error);
Creates a UDP socket and sets the default destination to the given address.
fn listen
fn listen(addr: ip::addr, port: u16, options: listen_option...) (net::socket | net::error);
Creates a UDP socket bound to an interface.
fn recv
fn recv(sock: net::socket, buf: []u8) (size | net::error);
Receives a UDP packet from a connected UDP socket.
fn recvfrom
fn recvfrom(sock: net::socket, buf: []u8, src: nullable *ip::addr, port: nullable *u16) (size | net::error);
Receives a UDP packet from a bound socket.
fn send
fn send(sock: net::socket, buf: []u8) (size | net::error);
Sends a UDP packet to a connected UDP socket.
fn sendto
fn sendto(sock: net::socket, buf: []u8, dest: ip::addr, port: u16) (size | net::error);
Sends a UDP packet using this socket.