Answer the question
In order to leave comments, you need to log in
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;
});
[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 в котором я как раз не могу найти никакого упоминания об адресе клиента
Answer the question
In order to leave comments, you need to log in
Try like this.
io.on('connection', function (socket) {
console.log(socket.handshake.address);
});
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 questionAsk a Question
731 491 924 answers to any question