Answer the question
In order to leave comments, you need to log in
How to limit the number of requests?
There is a server on Node JS with websockets. I use the ws library and there is no built-in function to limit the number of requests.
I tried to make a restriction through Nginx , but web sockets send only 1 HTTP request, and then the WebSocket protocol enters, so you can’t restrict it through it.
The last option was the idea for each connection to make a variable that is incremented by each request and every N seconds it is reset for everyone, but maybe there are some better or lower-level options?
Answer the question
In order to leave comments, you need to log in
Try just doing wss.close() where wss is the WebSocketServer instance when the number of connections reaches the limit. Then, if any of the connections closes, create a new WebSocketServer.
or, if there is a limit, immediately close the newly created connection in the wss.on('connection' ...) event handler.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question