如何知道给定池中连接套接字的数量

时间:2018-01-02 13:54:12

标签: node.js socket.io

标题中的所有内容。

io.on('connection', (socket) => {
  socket.join('somepool');
  // Here I want to know how many socket's connections are opened in the given pool
  // Something like:
  io.in('somepool').length;
});

1 个答案:

答案 0 :(得分:1)

您可以使用io.sockets.clients('somepool')让所有连接的客户端和io.sockets.clients('somepool').length获取连接数。

相关问题