Answer the question
In order to leave comments, you need to log in
How to make a chat cluster?
I am writing a chat that will be with a large number of connections.
The chat requires checking users for a ban.
In order to keep many connections I use cluster
var cluster = require('cluster'),
numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
}
if (cluster.isWorker) {
var io = require('socket.io').listen(2001);
io.sockets.on('connection', function (socket) {
console.log('connected to worker id ', cluster.worker.id);
});
io.sockets.on('user-message', function (socket) {
// здесь не знаю что делать
});
}
USERS = {
1: {id: 1, banned: false},
2: {id: 3, banned: true}
......
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question