Reputation: 136
Is it possible to limit socket io connections number in nodejs ?
I know one can configure limit by changing the server TCP settings, but I am looking for a way to do this in nodejs.
Upvotes: 3
Views: 3589
Reputation: 29172
You can implement it very easy:
var connectionsLimit = 1
io.on('connection', function (socket) {
if (io.engine.clientsCount > connectionsLimit) {
socket.emit('err', { message: 'reach the limit of connections' })
socket.disconnect()
console.log('Disconnected...')
return
}
})
Upvotes: 6