velt/net/udp
API referenceUDP sockets. Addresses are "host:port" strings. For a walkthrough, read the guide.
Exports
.port).DatagramA received datagram.UdpSocketA bound UDP socket: a Copy handle like std/net's TcpStream (async methods take this by copy, so it can be used repeatedly and from several tasks), released by close(); after that, every copy throws IoError EBADF.Re-exported from velt/net/udp/udp_socket
async function bindUdp(addr: string): Promise<UdpSocket>Binds a UDP socket to "host:port" (port 0 picks a free port; read it from .port).
Re-exported from velt/net/udp/datagram
A received datagram.
Returned byUdpSocket.recvFrom
data: u8[]No doc comment yetaddr: stringThe sender, "ip:port" (reply with socket.sendTo(x, d.addr)).
constructor(data: u8[], addr: string)No doc comment yettext(): stringThe payload as UTF-8 text (invalid bytes become U+FFFD).
Re-exported from velt/net/udp/udp_socket
A bound UDP socket: a Copy handle like std/net's TcpStream (async methods take this by
copy, so it can be used repeatedly and from several tasks), released by close(); after
that, every copy throws IoError EBADF.
Returned bybindUdp
| Field | Type | Description |
|---|---|---|
| port | number | The bound local port (useful after binding port 0). |
async sendTo(data: u8[], addr: string): Promise<i64>Sends one datagram to "host:port"; resolves with the number of bytes sent.
async sendTextTo(text: string, addr: string): Promise<i64>Sends text as UTF-8.
async recvFrom(max: u64 = 0): Promise<Datagram>The next datagram (at most max bytes are kept; 0 = up to 64 KiB).
setBroadcast(on: bool)Allows sending to broadcast addresses.
close()Closes the socket (operations in flight finish first).