fn main(){
let url: Url = "http://url.com".parse().unwrap();
let url2 = url.clone();
let host = url2.host_str().unwrap();
let port = url2.port_or_known_default().unwrap();
let mut i = 0;
let mut a = Vec::new();
while i < 300 {
println!("{}",i);
let mut stream = TcpStream::connect((host,port)).unwrap();
stream.flush().unwrap();
a.push(stream);
i+=1;
}
println!("finish")
Note that the server could have rate-limit that limits your connections per second.
Also it could detect DoS and ban IP address doing many connections in a short amount of time.
It show me open files is 12800 but If i open New terminal outside of vscode the open files only 248. This is why rust error when TcpStream more than 248. I think vscode Give us big open files limit for developping . However in mac os system only give us open files 248 for protect system.
Yeah, that's could be the case. However I'm not a mac user so I don't have machine to check.
Even if that's the case, getting file limit should be a clearer error in Rust side ?
On Linux, after setting ulimit -n 16, I got:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 24, kind: Other, message: "Too many open files" }', src/main.rs:17:63
Sorry i am New here so i have reply limit first day. I create a New account just now.
I tried same thing in linux. It has error but the error is 'Too many open files' rather than 'can not look up address' in mac os. Both of them In same case but the error different.
And i tried set ulimit -n 16 in a New shell session. The error messag is same : failed to lookup address information ....