[英]I'm trying to return socket id?
I'm trying to use express.io module for the first time and I like it. 我正在尝试第一次使用express.io模块,我喜欢它。 It's really extended part of socket.io and express.js. 它实际上是socket.io和express.js的扩展部分。
I'm trying to return socket.id in app.io.route event. 我正在尝试在app.io.route事件中返回socket.id。 How can I get client unique id using express.io? 如何使用express.io获取客户端唯一ID?
app.io.route('debug', function(socket) { console.log( socket.id ); });
The route
function receives a SocketRequest object, so you'll need the following: route
函数接收一个SocketRequest对象,因此您需要以下内容:
app.io.route('debug', function (req) {
console.log( req.io.id );
});
You can also access the socket.io socket directly ( req.socket
) if needed, but you should probably use the RequestIO object above if possible. 如果需要,您还可以直接访问socket.io套接字( req.socket
),但如果可能的话,应该使用上面的RequestIO对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.