method TcpStream.connect
Connects to addr (TCP_NODELAY is set). timeout bounds the whole attempt.
Example:
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 netSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
addr | SocketAddr |
timeout | Duration? = none |
Returns
Errors
NetError- `Unavailable` (refused, unreachable), `Timeout`, `AccessDenied`, `Cancelled`.
Effects
net
Defined in: std/net/net.oxl:494