A
A
Andrey Puzov2015-04-03 12:38:03
Node.js
Andrey Puzov, 2015-04-03 12:38:03

How to get the IP address of a local network computer in node.js?

Good afternoon.
I'm trying to write an in-company chat (the most beginner node.js-ist)

var io = require('socket.io').listen(app.listen(port));
io.sockets.on('connection', function(client){

how to find out who came to the chat?
I think that you can immediately write to IP - hello, Vasya.
only now I can’t figure out for a day how to accept the address of the local computer in socket.io (or something else) (latest version, 1.3.5, windows 7-64).
your own - you can, it turns out, someone else's - no way.
stack tips don't work. There, too, people suffer, I see. it worked for someone, someone didn’t
try a lot - the twisted ball doesn’t go. here's what's left:
var adr = client.handshake.address;
   console.log(adr);
   var socketId = client.id;
   var clientIp = client.manager.handshake[socketId].address;
   console.log(client.request.headers);
   console.log(client.handshake.headers['x-forwarded-for'] || client.handshake.address.address);
   console.log(client.request.connection.remoteAddress);
    var address = client.handshake.address;
    console.log("New connection from " + address.address + ":" + address.port);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2015-04-03
@k12th

And then Vasya will be fired, and Petya will come to his computer, and he will still write “hello, Vasya” to him? Or some sly thread from the neighbor’s computer will write to the chat “I’m a goosefil!” at lunchtime.
Why not do the good old authorization with a login-password?

A
Andrey Puzov, 2015-04-03
@puzzlo

Vasya will be fired - I will replace Jason's file with SP and first name and last name with the one whom they
did not want to take precisely so as not to write every time - I am Annabelle, the password for such and such a
chat is not for conversations, but for work
"to make documents for LLC "Sweet Pretzel" "
mark masha and say, send,
and similar
login should not cause inconvenience. just went to the address and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question