Socket.IO将查询参数混合在不同的命名空间中

时间:2022-04-20 19:42:33

I'm having trouble with query parameters in socket.io.

我在socket.io中遇到查询参数问题。

Server Side:

var io = require('socket.io')(server);
io.of('/1').on('connection', function(socket){
  console.log(socket.request._query['test']);
});
io.of('/2').on('connection', function(socket){
  console.log(socket.request._query['test']);
});
io.of('/3').on('connection', function(socket){
  console.log(socket.request._query['test']);
});

Client side:

io('/1', {
    query: 'test=1'
});
io('/2', {
    query: 'test=2'
});
io('/3', {
    query: 'test=3'
});

Prints:

1
1
1

Instead of:

1
2
3

The rest is just a default express scaffold.

其余的只是一个默认的快速脚手架。

Why is the query parameter always 1?

为什么查询参数总是1?

Thanks.

1 个解决方案

#1


0  

io('/1', {
    query: 'test=1',
    multiplex: false
});
io('/2', {
    query: 'test=2',
    multiplex: false
});
io('/3', {
    query: 'test=3',
    multiplex: false
});

Does the trick. See https://github.com/socketio/socket.io/issues/2632

诀窍。请参阅https://github.com/socketio/socket.io/issues/2632

#1


0  

io('/1', {
    query: 'test=1',
    multiplex: false
});
io('/2', {
    query: 'test=2',
    multiplex: false
});
io('/3', {
    query: 'test=3',
    multiplex: false
});

Does the trick. See https://github.com/socketio/socket.io/issues/2632

诀窍。请参阅https://github.com/socketio/socket.io/issues/2632