Skip to content
velt/net/udp exports

velt/net/udp

API reference

UDP sockets. Addresses are "host:port" strings. For a walkthrough, read the guide.

import { bindUdp } from "velt/net/udp";

Exports

functionasync

bindUdp

#std/net/udp/udp_socket.vlt:54

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.

data: u8[]No doc comment yet
addr: string

The sender, "ip:port" (reply with socket.sendTo(x, d.addr)).

constructor(data: u8[], addr: string)No doc comment yet
text(): string

The 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.

FieldTypeDescription
port numberThe 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).