engine.io-客户端中的forceNew

forceNew in engine.io-client

我想用多个连接测试我的 engine.io 服务器。 我试图循环打开套接字,但输出只有一个套接字。

在 socket.io-client 中,我添加了 forceNew: true 并修复了问题,但无法使用 engine.io-client。

for (var i=0;i<10;i++){
    var socket = require('engine.io-client')('ws://localhost');
    socket.on('open', function(){

        console.log('socket opened : '+socket.id);

        socket.on('message', function(data){
          console.log('data is '+data);
        });

        socket.on('close', function(){
          console.log('socket closed : '+socket.id);
        });
    });
}

使用 socket.io-客户端,您必须设置 multiplex: false

It creates a new Manager for the given URL, and attempts to reuse an existing Manager for subsequent calls, unless the multiplex option is passed with false. Passing this option is the equivalent of passing 'force new connection': true.

更多信息位于:http://socket.io/docs/client-api/

但是,"engine.io-client" 似乎没有这样的实现,我认为也不会有。

The recommended framework for building realtime applications is Socket.IO, since it provides fundamental features for real-world applications such as multiplexing, reconnection support, etc.

发件人:https://github.com/Automattic/engine.io