websockets-rs / rust-websocket

A WebSocket (RFC6455) library written in Rust
http://websockets-rs.github.io/rust-websocket/
MIT License
1.55k stars 223 forks source link

localhost does not resolve #135

Open alex-shapiro opened 7 years ago

alex-shapiro commented 7 years ago

I tried to open an async connection to a server running locally at ws://localhost:4000 and received the following error:

IoError(Error { repr: Os { code: 61, message: "Connection refused" } })

However, the following work:

I'm not exactly sure what's going on. It's not a big deal - I'm manually resolving localhost to 127.0.0.1 - but I'm kind of curious.

illegalprime commented 7 years ago

Good catch! It's probably this code: https://github.com/cyderize/rust-websocket/blob/master/src/client/builder.rs#L800

Instead of calling next() you should create a TcpStream with that iterator and then turn it into an async one with the async TcpStream's API.

alex-shapiro commented 7 years ago

That means the DNS lookup would be done synchronously, right?

illegalprime commented 7 years ago

hmm... that's a good point. I wonder how hyper 0.11 is doing it

alex-shapiro commented 7 years ago

Looks like Hyper wraps a synchronous DNS call inside a future: https://github.com/hyperium/hyper/blob/master/src/client/dns.rs#L52.

illegalprime commented 7 years ago

We can try looping over the ToSocketAddr in the future (make one async DNS call, if that fails try again). This would get a really complicated type though.