如何获得NodeJS客户端ID?

时间:2014-04-18 06:45:31

标签: node.js session socket.io

运行NodeJ我可以看到一种客户端ID:

debug - emitting heartbeat for client hg5ZurBEi8R3Ehf5kuBJ
debug - websocket writing 2::
debug - set heartbeat timeout for client hg5ZurBEi8R3Ehf5kuBJ
debug - got heartbeat packet
debug - cleared heartbeat timeout for client hg5ZurBEi8R3Ehf5kuBJ
debug - set heartbeat interval for client hg5ZurBEi8R3Ehf5kuBJ

我正在使用socket.io。有办法获得“hg5ZurBEi8R3Ehf5kuBJ”吗?一种app.session_id。

1 个答案:

答案 0 :(得分:1)

如果你想在服务器上获取它:

var io = require('socket.io').listen(80);

io.sockets.on('connection', function (socket) {
    console.log(socket.id); //client ID
});