method TcpStream.connectHost
Resolves host (a name or numeric address) and connects to the first address that accepts.
Example:
use std.net { TcpStream }
fn main() io, net {
match TcpStream.connectHost("", 80, 1s) {
TcpStream c => {
print("connected")
_ = c.close()
}
NetError _ => print("empty host rejected")
}
}Output
empty host rejected
pub(api) static fn connectHost(host: str, port: u16, timeout: Duration? = none) -> TcpStream | NetError netSince. 1.0.0-beta
Parameters
| Name | Type |
|---|---|
host | str |
port | u16 |
timeout | Duration? = none |
Returns
Errors
NetError- `Unavailable` (name not found, refused), `Timeout`, `AccessDenied`, `Cancelled`.
Effects
net
Defined in: std/net/net.oxl:520