Thanks for your help billywhizz.

On Mon, Feb 27, 2012 at 7:59 PM, 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
>



-- 
--
-- 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

Reply via email to