0

k so I try for 1 hour now and it still not working

I want to get id of every socket.io user so I tried this:

var socket_list = new Array();

io.on('connection', function (socket) {... socket_list.push(socket); ...}

then

for(var soc in socket_list) { console.log(soc.id); }

but it still undefined. how to fix? thanks

it looks simple but just not working

also tried console.log(socket_list) and it worked

Shark
  • 23
  • 4

2 Answers2

0

socket_list is an array. So use an appropriate loop:

for(var i = 0; i < socket_list.length; i++) { 
    console.log(socket_list[i].id); 
}
friedi
  • 4,350
  • 1
  • 13
  • 19
-1

This is how I did it:

io.sockets.sockets.forEach(function (socket) {
  console.log(socket.id);
});
kYuZz
  • 1,572
  • 4
  • 14
  • 25