Address hostname failure on Windows

49 views
Skip to first unread message

Greg Reimer

unread,
Jul 29, 2015, 1:44:03 AM7/29/15
to nodejs
This works on OS X, but fails on Windows 7 (io.js 2.5.0):

    var http = require('http')

    var server = http.createServer(function(req, res) {
      res.end('hello')
    }).listen(0, function() {

      var addr = server.address()

      http.get({
        hostname: addr.address, // <-- this
        port: addr.port,
        path: '/foo',
      }, function(res) {
        console.log('hello')
        process.exit(0)
      })
    })

If I change addr.address to 'localhost' it starts working, but I'm curious why. Here's the error:

    Error: connect EADDRNOTAVAIL :::51539
        at Object.exports._errnoException (util.js:812:11)
        at exports._exceptionWithHostPort (util.js:835:20)
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1048:14)

Thanks.

Ryan Schmidt

unread,
Jul 29, 2015, 9:03:31 AM7/29/15
to nod...@googlegroups.com
I don't know the answer to your question, but it looks like you're trying to have your web server send an http request to itself. That's usually an indication that you've structured your program incorrectly; it shouldn't ever be necessary to do that.

Greg Reimer

unread,
Jul 29, 2015, 11:53:02 AM7/29/15
to nodejs, googl...@ryandesign.com
Thanks. I think there are a few valid use cases for it, for example as part of a testing function, which is what this was.

Ryan Graham

unread,
Jul 29, 2015, 11:04:10 PM7/29/15
to nodejs, googl...@ryandesign.com

Your listening address is the equivalent of 0.0.0.0, which Windows does not like to connect to. The solution for your IPv6 case is the same as for IPv4, which is to give a host address. Unfortunately that means on Windows you can't do what you're trying to do with an ADDRANY listening socket.

~Ryan


--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/62f97d35-a04c-4bad-ad8e-417f6fce408b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages