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")
}
}Вывод
refused
pub(api) static fn connect(addr: SocketAddr, timeout: Duration? = none) -> TcpStream | NetError netС версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
addr | SocketAddr |
timeout | Duration? = none |
Возвращает
Ошибки
NetError- `Unavailable` (refused, unreachable), `Timeout`, `AccessDenied`, `Cancelled`.
Эффекты
net
Определено в: std/net/net.oxl:494