Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · udp

Docs

std/udp

On this page

Index

Types

UdpConn

struct UdpConn {}

A UDP socket: bound by listen (any peer) or connected by dial (one peer). A handle; close is idempotent.

Source: std/udp.xo:7

UdpConn.read_from

fn (c: UdpConn) read_from(max: Int = 65535) -> (Bytes, Str) ! NetErr uses net

The next datagram and its sender (“ip:port”); a datagram longer than max is cut to max, the rest discarded (Go’s ReadFrom).

Source: std/udp.xo:18

UdpConn.write_to

fn (c: UdpConn) write_to(data: Bytes, addr: Str) -> () ! NetErr uses net

Sends data as one datagram to addr; Net.only checks addr.

Source: std/udp.xo:20

UdpConn.read

fn (c: UdpConn) read(max: Int = 65535) -> Bytes ! NetErr uses net

The next datagram from a dialed socket’s peer.

Source: std/udp.xo:22

UdpConn.write

fn (c: UdpConn) write(data: Bytes) -> () ! NetErr uses net

Sends data as one datagram to a dialed socket’s peer.

Source: std/udp.xo:24

UdpConn.local_addr

fn (c: UdpConn) local_addr() -> Str

The socket’s own address (“ip:port”).

Source: std/udp.xo:26

UdpConn.close

fn (c: UdpConn) close()

Closes the socket; a waiting read fails with Io.

Source: std/udp.xo:28

Functions

listen

pub fn listen(n: Net, addr: Str) -> UdpConn ! NetErr uses net.listen

A socket bound to addr (“host:port”; port 0 lets the system choose, local_addr reports it): Go’s net.ListenPacket(“udp”, addr).

Source: std/udp.xo:11

dial

pub fn dial(n: Net, addr: Str) -> UdpConn ! NetErr uses net.dial

A socket connected to addr: read and write exchange datagrams with that peer only (Go’s net.DialUDP).

Source: std/udp.xo:14

↑ index