node.js – Limiting connections to Socket.IO by IP


You need to set a connection limit to Socket.IO (node.js). No more than 3 connections from 1 IP. How can this be done?


Normally, it seems like nothing, only manually check how many connections are already hanging, you can check ip by adding them to JSON or Array and comparing the value, for example, make JSON

{"ip" : {
"" : "1",
"" : "2"}

and a simple if check how many connections are from this ip, if there are more than 3 connections, the main thing is to delete the record at 0 connections so that memory does not go to "infinite" JSON

ps: and it will be more honest not to drop the connection when exceeding 3, but to throw a message about exceeding the permissible number of ip.

Scroll to Top