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