简体   繁体   中英

I'm trying to return socket id?

I'm trying to use express.io module for the first time and I like it. It's really extended part of socket.io and express.js.

I'm trying to return socket.id in app.io.route event. How can I get client unique id using express.io?

 app.io.route('debug', function(socket) { console.log( socket.id ); }); 

The route function receives a SocketRequest object, so you'll need the following:

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.

Routing documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM