I have a cluster.js with the following code:
var numOfCpus = 16;
var cluster = require('cluster');
if (cluster.isMaster) {
for (var i = 0; i < numOfCpus; i++) {
cluster.fork();
}
console.log("master is running");
} else {
console.log('Worker %d started', cluster.worker.id);
var server = app.listen(8887);
var io = require('socket.io').listen(server);
var live_data = io.of('/live_data');
live_data.on('connection',function(socket){
console.log('Connected: %s', socket.id);
});
}
My client application works fine when the numOfCpus = 1 in cluster.js. When I have anything more than 1, the socket.io starts giving the following error:
Do I have to do anything special to make socket.io work with multiple node workers? Any help will be highly appreciated. Thanks.