UdpSocket¶
Import: import system.net;
Read the usage guide for examples and common tasks. This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation.
UdpSocket¶
An owned UDP socket with explicit message boundaries and bounded receive buffers.
bind¶
Binds an endpoint; port zero selects an ephemeral port.
public static async fun bind(
host: string,
port: int,
token: Option<CancellationToken> = Option.None
): Result<UdpSocket, IoError>
local_host¶
Numeric bound interface address.
local_port¶
Actual bound UDP port.
send¶
Sends one datagram of at most 65507 bytes with optional deadline and cancellation.
public async fun send(
host: string,
port: int,
data: byte[],
timeout_ms: int = 0,
token: Option<CancellationToken> = Option.None
): Result<int, IoError>
receive¶
Receives one message, reporting truncation explicitly; a concurrent receive returns EBUSY.
public async fun receive(
max_bytes: int = 65535,
timeout_ms: int = 0,
token: Option<CancellationToken> = Option.None
): Result<UdpDatagram, IoError>
set_broadcast¶
Enables or disables sending to broadcast endpoints.
set_ttl¶
Sets outgoing IP time-to-live to a value between 1 and 255.
close¶
Closes the owned socket and wakes pending receives; repeated closure succeeds.