Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果我使用 express 和 socket.io 运行 nodejs 服务器,如何将并发连接数限制为任意数量?即:在握手期间,检查是否达到限制,如果是,拒绝连接?
在您的connection事件处理程序中,您可以检查以下值:
connection
io.sockets.clients().length
并据此决定做什么。如果您只想要连接的客户端:
io.sockets.clients().filter(function(s) {return !s.disconnected;}).length