简体   繁体   English

我正在尝试返回套接字ID?

[英]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对象。

Routing documentation 路由文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jquery 在我试图抓取的 div 元素的 id 上获得“未定义” - jquery getting an 'undefined' on the id of a div element I'm trying to grab 我正在尝试获取我的 Firestore 文档 ID - I'm trying to get my firestore document id 我正在尝试根据它们的id在html中命令div - I'm trying to order divs in html based on the id of them 我正在尝试使用json文件,但无法返回数据 - I'm trying to use the json file, but it can't be return data 我正在尝试在 javascript 中获取值以 JSON 格式在 PHP 中返回它 - I'm trying to get value in javascript to return it in PHP in JSON format 我正在尝试返回尚未完成的任务 - I'm trying to return the task that has not been completed 我正在尝试使用他们的 ID 从公会中获取成员,但现在我使用的变量返回未定义 - I'm trying to fetch members from a guild using their ID but now the variable I'm using returns Undefined 我是 firebase 的新人,我正在尝试获取父集合的 ID 文档,但我无法弄清楚 - I'm new in firebase and I'm trying to get id document for parent collection but I can't figure it out 当我尝试附加data-id时; 我有一个错误 - When I'm trying to append data-id; I got an error 我正在尝试通过 make id 获取模型,但我不能;无法工作 - I'm trying to fetch model through make id but i can;t working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM