OxL Reference

method TcpListener.bind

Binds and listens (SO_REUSEADDR is set). Port 0 picks a free port: read it back from the field local.

Example:

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

fn main() -> () | ParseError  io, net {
  let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)
  match l {
    TcpListener ok => {
      print("bound")
      _ = ok.close()
    }
    NetError _ => print("cannot bind")
  }
}
Output
bound
pub(api) static fn bind(addr: SocketAddr, backlog: i64 = 1024) -> TcpListener | NetError  net

Since. 1.0.0-beta

Parameters

NameType
addrSocketAddr
backlogi64 = 1024

Returns

TcpListener

Errors

  • NetError
  • `Unavailable` (address in use, no resources), `AccessDenied` (privileged port), `ProtocolError`.

Effects

net

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

See also