Thanks for the help! I think I'm getting somewhere now. The code provided had a few issues, but now, when I try running this, I get no prints at all! This is really confusing me because I'm pretty sure I'm following everything correctly.
async fn resolvable(ip: String, port: u32, timeout_seconds: u64) -> Result<tokio::net::TcpStream, Box<dyn std::error::Error + Send + Sync>> {
tokio::time::timeout(std::time::Duration::from_secs(timeout_seconds), tokio::net::TcpStream::connect(format!("{}:{}", ip, port)))
.await?
.map_err(|err| Box::new(err) as Box<dyn std::error::Error + Send + Sync>)
}
#[tokio::main]
async fn main() {
let mut jhs = Vec::new();
for port in 0..101 {
let jh = tokio::spawn(async move {
match resolvable("127.0.0.1".into(), port, 5).await {
Ok(_) => println!("Port {} open!", port),
Err(err) => println!("Error: timed out: {} Port {} closed.", err, port),
}
});
jhs.push(jh);
}
for jh in jhs {
jh.await;
}
}
Am I overlooking anything?
I discovered this post:
I'm not sure why, but doing the vector solution solved all my issues. If anyone can expand on why, this would help me a ton!
Other than that, thanks I finally figured it out!!!