socket.IO: how can i get the socketid when i emit

2019-08-06 02:37发布

I want to emit a action to a specific client using socket.io 1.0.

After reading Sending message to a specific ID in Socket.IO 1.0 , I know I can use:

io.sockets.connected[socketid].emit()

to emit a action to specific person.

But how can I get the socketid?

I used to write like this : socket.id=nickName, but it's wont work.

1条回答
何必那么认真
2楼-- · 2019-08-06 02:57

Simply access id property of socket object:

io.on('connection', function(socket) {
    console.log(socket.id);
});
查看更多
登录 后发表回答