OxL Reference

data TcpListener

A listening TCP socket. Close it with close() (or let it go out of scope after close).

Example:

oxl✓ checked in CI
use std.net { SocketAddr, TcpListener }

fn main() -> () | NetError | ParseError  io, net {
  let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)?
  print("listening: {l.local.port > 0}")
  l.close()?
}
Output
listening: true
@must_close
pub(api) data TcpListener

Thread safety. `accept` may be called by one task at a time; the accepted streams belong to the tasks that handle them.

Since. 1.0.0-beta

Fields

pub(api) local: SocketAddr

The address the socket listens on.

Methods

bind(addr: SocketAddr, backlog: i64) -> TcpListener | NetError net
Binds and listens (SO_REUSEADDR is set).
accept(timeout: Duration?) -> TcpStream | NetError net
Waits for the next connection.
close() -> () | NetError net
Closes the listening socket.

Defined in: std/net/net.oxl:348

See also