std.net.udp
datagram sockets; send_to/recv_from, or connect once then send/recv
Datagram
Section titled “Datagram”pub Datagram :: struct { len: usize, from: addr::SocketAddr,}recv_from result: byte count + sender
UdpSocket
Section titled “UdpSocket”pub UdpSocket :: struct { sock: socket::Socket,}UdpSocket.send_to
Section titled “UdpSocket.send_to”pub send_to :: fn(self: *Self, data: []const u8, to: addr::SocketAddr) -> usize ! NetErrorone datagram to to; bytes sent
UdpSocket.recv_from
Section titled “UdpSocket.recv_from”pub recv_from :: fn(self: *Self, buf: []u8) -> Datagram ! NetErrorone datagram into buf; truncated if longer than buf
UdpSocket.connect
Section titled “UdpSocket.connect”pub connect :: fn(self: *Self, to: addr::SocketAddr) -> void ! NetErrordefault peer for send/recv; drops datagrams from others
UdpSocket.send
Section titled “UdpSocket.send”pub send :: fn(self: *Self, data: []const u8) -> usize ! NetErrorto the connected peer; must call connect first
UdpSocket.recv
Section titled “UdpSocket.recv”pub recv :: fn(self: *Self, buf: []u8) -> usize ! NetErrorfrom the connected peer; bytes read
UdpSocket.set_broadcast
Section titled “UdpSocket.set_broadcast”pub set_broadcast :: fn(self: *Self, on: bool) -> void ! NetErrorUdpSocket.set_read_timeout
Section titled “UdpSocket.set_read_timeout”pub set_read_timeout :: fn(self: *Self, ms: i32) -> void ! NetErrorUdpSocket.local_addr
Section titled “UdpSocket.local_addr”pub local_addr :: fn(self: *Self) -> addr::SocketAddr ! NetErrorUdpSocket.close
Section titled “UdpSocket.close”pub close :: fn(self: *Self)pub bind :: fn(sa: addr::SocketAddr) -> UdpSocket ! NetErrorudp socket bound to sa; sets SO_REUSEADDR
unbound
Section titled “unbound”pub unbound :: fn() -> UdpSocket ! NetErrorunbound socket; the os picks a port on first send