Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
Development · Evolving reference

TcpListener

Owns one nonblocking TCP acceptance socket with explicit close authority. TryListen transactionally opens/binds/listens. TryAccept attempts one acceptance without waiting; WouldBlock is not a fake empty stream. Successful streams own independent close authority and outlive this listener. Mutable receiver loans serialize operations; shared use across threads needs external synchronization. Move closes the source logically. Destruction closes once without flushing.

Sn is under heavy development. This reference includes the intended 1.0 design; features may be incomplete in the current compiler. Read the status →

Module std.net

import std.net;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

TcpListener

pub final class TcpListener

Owns one nonblocking TCP acceptance socket with explicit close authority. TryListen transactionally opens/binds/listens. TryAccept attempts one acceptance without waiting; WouldBlock is not a fake empty stream. Successful streams own independent close authority and outlive this listener. Mutable receiver loans serialize operations; shared use across threads needs external synchronization. Move closes the source logically. Destruction closes once without flushing.

TcpListener.init

pub init()

Creates a closed owner without native effects.

TcpListener.init

pub init(Source: readonly Self&) = delete;

Rejects duplicated close authority. Source: Existing owner.

TcpListener.init

pub init(Source: mut Self&&)

Transfers authority without native I/O, leaving source closed. Source: Writable source consumed by movement.

TcpListener.operator

pub fn operator =(Source: readonly Self&) -> void = delete;

Rejects copying ownership. Source: Existing owner. Return: No runtime result; this assignment is deleted and cannot be invoked.

TcpListener.operator

pub fn operator =(Source: mut Self&&) -> void = delete;

Requires explicit close before replacement. Source: Existing owner. Return: No runtime result; this assignment is deleted and cannot be invoked.

TcpListener.IsClosed

pub IsClosed: bool;

Observes closed/moved state without native calls. Return: True when no close authority remains.

TcpListener.TryListen

pub static fn TryListen(mut Local: Endpoint, Backlog: i32) -> Result<Self, NetworkError>

Opens/binds/listens on an exact numeric local endpoint. Local: Owned endpoint; port zero requests ephemeral local binding. Backlog: Positive native queue hint, default 128; host may cap it. Return: Sole listener owner or typed failure; failed setup releases acquisition. Warning: Acquires resources but performs no DNS or readiness wait.

TcpListener.TryListen

pub static fn TryListen(mut Local: Endpoint) -> Result<Self, NetworkError>

Supplies the omitted arguments to TryListen. Note: Defaults: Backlog = 128. Local: Same input, ownership and lifetime contract as the full operation. Return: The full synchronous operation's owned success value or typed failure.

TcpListener.TryAccept

pub fn TryAccept() -> Result<TcpStream, NetworkError>

Attempts one nonblocking acceptance with independent stream ownership. Return: Sole accepted stream or typed failure, including WouldBlock. No stream or descriptor is published on failed admission.

TcpListener.AcceptAsync

pub async fn AcceptAsync(Token: CancellationToken) -> Task<Result<TcpStream, NetworkError>>

Accepts one independently owned stream without blocking a worker. Token: Owned cancellation observation, inert by default. Return: Sole accepted stream or typed error. Receiver remains borrowed until completion; readiness retries never release listener close authority.

TcpListener.AcceptAsync

pub fn AcceptAsync() -> Task<Result<TcpStream, NetworkError>>

Supplies the omitted arguments to AcceptAsync. Note: Defaults: Token = CancellationToken(). Return: Exact full-operation result; no additional async frame is created.

TcpListener.AcceptAsync

pub async fn AcceptAsync(Limit: Deadline, Token: CancellationToken) -> Task<Result<TcpStream, NetworkError>>

Accepts against one unchanged absolute deadline. Limit: Finite compatible monotonic boundary or Endless; checked before attempts. Token: Owned cancellation observation, checked before deadline. Return: Owned stream or typed cancellation/timeout/domain/native failure.

TcpListener.AcceptAsync

pub fn AcceptAsync(mut Limit: Deadline) -> Task<Result<TcpStream, NetworkError>>

Supplies the omitted arguments to AcceptAsync. Note: Defaults: Token = CancellationToken(). Limit: Same input, ownership and lifetime contract as the full operation. Return: Exact full-operation result; no additional async frame is created.

TcpListener.ReadLocalEndpoint

pub fn ReadLocalEndpoint() -> Result<Endpoint, NetworkError>

Copies numeric bound endpoint including selected ephemeral port. Return: Independent endpoint or typed closed/native failure.

TcpListener.Close

pub fn Close() -> Result<void, NetworkError>

Consumes listener close authority once; closed is immediate success. Return: Native completion/failure; already accepted streams remain owned independently.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library