std/udp
On this page
Index
- type
UdpConn- method
UdpConn.read_from - method
UdpConn.write_to - method
UdpConn.read - method
UdpConn.write - method
UdpConn.local_addr - method
UdpConn.close
- method
- fn
listen - fn
dial
Types
UdpConn
struct UdpConn {}A UDP socket: bound by listen (any peer) or connected by dial
(one peer). A handle; close is idempotent.
UdpConn.read_from
fn (c: UdpConn) read_from(max: Int = 65535) -> (Bytes, Str) ! NetErr uses netThe next datagram and its sender (“ip:port”); a datagram longer than max is cut to max, the rest discarded (Go’s ReadFrom).
UdpConn.write_to
fn (c: UdpConn) write_to(data: Bytes, addr: Str) -> () ! NetErr uses netSends data as one datagram to addr; Net.only checks addr.
UdpConn.read
fn (c: UdpConn) read(max: Int = 65535) -> Bytes ! NetErr uses netThe next datagram from a dialed socket’s peer.
UdpConn.write
fn (c: UdpConn) write(data: Bytes) -> () ! NetErr uses netSends data as one datagram to a dialed socket’s peer.
UdpConn.local_addr
fn (c: UdpConn) local_addr() -> StrThe socket’s own address (“ip:port”).
UdpConn.close
fn (c: UdpConn) close()Closes the socket; a waiting read fails with Io.
Functions
listen
pub fn listen(n: Net, addr: Str) -> UdpConn ! NetErr uses net.listenA socket bound to addr (“host:port”; port 0 lets the system choose,
local_addr reports it): Go’s net.ListenPacket(“udp”, addr).
dial
pub fn dial(n: Net, addr: Str) -> UdpConn ! NetErr uses net.dialA socket connected to addr: read and write exchange datagrams
with that peer only (Go’s net.DialUDP).