我使用套接字1.X和快递4和群集为服务器应用程序只对你有利在客户端的会话中丢失SOCKET IO不明白为什么
app.js
var app = require('express')();
var http = require('http').Server(app);
var redis = require('socket.io-redis');
var cluster = require('cluster');
// var sessionStore = new (require('connect-mongo')(express))({ db: "test" });
if(cluster.isMaster ){
// Count the machine's CPUs
var cpuCount = require('os').cpus().length;
console.log( "CORES : " + cpuCount );
// Create a worker for each CPU
for (var i = 0; i < cpuCount; i += 1) {
cluster.fork();
}
// Listen for dying workers
cluster.on('exit', function (worker) {
// Replace the dead worker,
// we're not sentimental
console.log('Worker %d died :(', worker.id);
cluster.fork();
});
} else {
var io = require('socket.io').listen(http);
io.adapter(redis({ host: 'localhost', port: 6379 }));
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
}
这是我的代码,并且不明白有时我错了,客户端会返回此错误
{&#34;代码&#34;:1,&#34;消息&#34;:&#34;会话ID未知&#34;}
我的所有活动都没有发出,我的应用无法正常继续
由于