OxL Reference

method TcpStream.connect

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

Example:

oxl✓ checked in 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")
  }
}
Output
refused
pub(api) static fn connect(addr: SocketAddr, timeout: Duration? = none) -> TcpStream | NetError  net

Since. 1.0.0-beta

Parameters

NameType
addrSocketAddr
timeoutDuration? = none

Returns

TcpStream

Errors

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

Effects

net

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

See also