Skip to content

TcpListener

1 min read

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.

TcpListener

An owned TCP listener; accepted connections retain independent ownership.

public class TcpListener

bind

Binds a listener; port zero selects an ephemeral port reported by local_port.

public static async fun bind(
    host: string,
    port: int,
    token: Option<CancellationToken> = Option.None
): Result<TcpListener, IoError>

local_host

Numeric interface address selected by the host.

public get local_host(): string

local_port

Actual bound port, including an automatically selected ephemeral port.

public get local_port(): int

accept

Accepts a connection with optional deadline and inherited cancellation.

public async fun accept(
    timeout_ms: int = 0,
    token: Option<CancellationToken> = Option.None
): Result<TcpStream, IoError>

close

Closes this listener and cancels pending accepts, preserving accepted streams.

public fun close(): Result<Unit, IoError>