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

method TcpStream.connect

Connects to addr (TCP_NODELAY is set). timeout bounds the whole attempt.

Example:

oxl✓ проверяется в CI
use std.net { SocketAddr, TcpStream }

fn main() -> () | ParseError  io, net {
  // nothing listens on port 1
  match TcpStream.connect(SocketAddr.parse("127.0.0.1:1")!, 1s) {
    TcpStream c => {
      print("connected")
      _ = c.close()
    }
    Unavailable _ => print("refused")
    NetError _ => print("other error")
  }
}
Вывод
refused
pub(api) static fn connect(addr: SocketAddr, timeout: Duration? = none) -> TcpStream | NetError  net

С версии. 1.0.0-beta

Параметры

ИмяТип
addrSocketAddr
timeoutDuration? = none

Возвращает

TcpStream

Ошибки

  • NetError
  • `Unavailable` (refused, unreachable), `Timeout`, `AccessDenied`, `Cancelled`.

Эффекты

net

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

См. также