A
A
Anton Anton2014-05-31 19:36:42
Node.js
Anton Anton, 2014-05-31 19:36:42

How to see the ip address of a connected client in socket.io?

I can't find it, and the documentation is very poor, unfortunately.
Here is the minimum sufficient code to reproduce the situation:

var port = 2280;
var io = require('socket.io').listen(port);
io.sockets.on('connection', function (socket) {
  debugger;
});

I start debugging like this:
[email protected]:~/node.js> node debug node_server.js 
< debugger listening on port 5858
connecting... ok
break in node_server.js:8
  6 
  7 
  8 var port = 2280;
  9 var io = require('socket.io').listen(port);
 10 
debug> cont
break in node_server.js:112
 110 io.sockets.on('connection', function (socket) {
 111 
 112    debugger;
 113 
 114    var client = Client(socket);
debug> repl
Press Ctrl + C to leave debug repl
> socket
{ nsp: 
   { name: '/',
     server: 
...дальше идет json в котором я как раз не могу найти никакого упоминания об адресе клиента

If there is information on the normal debugging of Node.JS (ideally from netbeans), I will be very grateful.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Yelpaev, 2014-05-31
@andreyelpaev

Try like this.

io.on('connection', function (socket) {
  console.log(socket.handshake.address);
});

UPD. This is how it should work.
io.on('connection', function (socket) {
   var id = socket.id;
   console.log(socket.manager.handshaken[id].address);
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question