Thank You billywhizz for that. Looks like os.getNetworkInterfaces() is renamed to os.networkInterfaces() since v0.6.0, as noted here - http://blog.nodejs.org/2011/11/05/node-v0-6-0/
Cheers --Sadique On Tue, Feb 28, 2012 at 6:29 AM, billywhizz <[email protected]> wrote: > if you want to listen on multiple interfaces and know which interface > a peer is using, then you would have to do something like this: > > var net = require("net"); > var os = require("os"); > > function connectionHandler(peer) { > console.log(peer.address()); > } > > var interfaces = os.getNetworkInterfaces(); > for(name in interfaces) { > var interface = interfaces[name]; > interface.forEach(function(entry) { > if(entry.family === "IPv4") { > var s = net.createServer(connectionHandler); > s.listen(80, entry.address); > console.log("listening on " + entry.address); > } > }); > } > > On Feb 27, 11:08 pm, Tim Whidden <[email protected]> wrote: > > Thanks all for your replies. > > > > Perhaps the question is really, is there anyway to query which network > > interface one's server is using? os.networkInterfaces() has the > information > > I'm looking for, but I don't understand how I can tell which interface is > > the proper one. > > > > Thanks, > > > > > > > > > > > > > > > > > > > > On Mon, Feb 27, 2012 at 5:48 PM, Ben Noordhuis <[email protected]> > wrote: > > > On Mon, Feb 27, 2012 at 23:25, billywhizz <[email protected]> wrote: > > > > as far as i know if you want to get the specific ip address of an > > > > interface then you will have to bind explicitly to that IP address > and > > > > not to "0.0.0.0" in order to get the correct IP from getsockname, > > > > which is the system call used under the hood. so, instead of doing: > > > > > > server.listen(80) or server.listen(80, "0.0.0.0") > > > > > > you need to do: > > > > > > server.listen(80, "10.11.12.100") > > > > > > replacing 10.11.12.100 with the IP address you want to listen on. > > > > >http://stackoverflow.com/questions/5759031/getsockname-always-returni. > .. > > > > > That's correct. This thread is a reworded version of > > >http://groups.google.com/group/nodejs/browse_thread/thread/f2a93fe022. > .. > > > > > -- > > > Job Board:http://jobs.nodejs.org/ > > > Posting guidelines: > > >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 post to this group, send email to [email protected] > > > To unsubscribe from this group, send email to > > > [email protected] > > > For more options, visit this group at > > >http://groups.google.com/group/nodejs?hl=en?hl=en > > > > -- > > -- > > -- Tim Whidden > > --http://twhid.com > > --http://mtaa.net > > -- > Job Board: http://jobs.nodejs.org/ > Posting guidelines: > 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 post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/nodejs?hl=en?hl=en > -- Job Board: http://jobs.nodejs.org/ Posting guidelines: 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 post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en
