OxL Справочник OxL
РусскийEnglish

data TcpListener

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

Example:

oxl✓ проверяется в 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()?
}
Вывод
listening: true
@must_close
pub(api) data TcpListener

Потокобезопасность. `accept` may be called by one task at a time; the accepted streams belong to the tasks that handle them.

С версии. 1.0.0-beta

Поля

pub(api) local: SocketAddr

The address the socket listens on.

Методы

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.

Определено в: std/net/net.oxl:348

См. также