Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set connect timeout on TcpStream

Tags:

tcp

rust

I am trying to connect to a server which is unreachable using the following code:

println!("Connecting");
TcpStream::connect(s).unwrap();
println!("Connected");

When I run the code, it gets stuck on second line.

Output:

Connecting
like image 717
spicavigo Avatar asked May 04 '15 03:05

spicavigo


1 Answers

greetings from 2020.

In the meantime the answer changed, it's no longer "can't be done easily" but is:

TcpStream::connect_timeout()

https://doc.rust-lang.org/std/net/struct.TcpStream.html#method.connect_timeout

like image 73
Aiyion.Prime Avatar answered Sep 30 '22 08:09

Aiyion.Prime