testing - 如何测试具有多个客户端的 socket.io 服务器?

标签 testing socket.io

我正在尝试为 socket.io 服务器编写测试。

io.on('connection', function (socket) {
  socket.on('say', function (msg) {
    socket.broadcast.emit('update', msg);
  });
});

每个客户端都会收到其他客户端发送的所有消息。我只是想测试一下。

为此,我的测试需要模拟多个客户端。但是 socket.io-client 重用了连接,这让这变得很困难。

我应该如何测试这段代码?

最佳答案

找到了。创建客户端时,使用选项 multiplex: false :

var client = io("http://localhost:3000", {multiplex: false});

根据文档:

When called, io() 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.

关于testing - 如何测试具有多个客户端的 socket.io 服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32484764/

相关文章:

javascript - 毕竟未捕获 TypeError : localStorage. removeItem 不是抛出的函数

testing - 使用 gcov [Linux/Fortran] 进行共享库覆盖率测试

sockets - node.js 和 socket.io : different connections for different "sessions"

node.js - 使用 Node.js 和 Socket.io 将更改推送到所有客户端

javascript - 当我将 JS 对象发送到 Node.js 服务器并要求返回相同的对象时,服务器发回修改后的对象

node.js - 在 Node 服务器上安装 SSL 证书

ios - 如何查看 XCUIElement 树?

testing - 没有设置 X11 DISPLAY 变量,但是这个程序执行了一个需要它的操作

javascript - 在 Angular version1 中,我如何测试我的 scope.$on 监听器是否被调用?

javascript - 400错误请求(使用node和socket.io制作游戏)