我想将 express.js 和 socket.io 会话合并在一起。下面是我的代码(socket.io 部分)
var io = require('socket.io').listen(app);
io.set('log level', 1);
io.sockets.on('connection', function (socket) {
console.log('client connected');
client.send(client.id);//send client id to client itself
socket.on('connect', function(){
console.log(socket.id + ' connected');
});
socket.on('disconnect', function(){
console.log(socket.id + ' disconnected');
});
});
我的 express.js 会话设置:
app.configure(function() {
//app.use(express.logger());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(__dirname + '/static'));
app.use(express.cookieParser());
app.use(express.session({store: MemStore({
reapInterval: 60000 * 10
}), secret:'foobar', key: 'express.sid'
}));
我的主要问题是在我的终端中,当用户从一个 URL 移动到另一个 URL 时,会话 ID 也会发生变化:但我不希望它被更改。
info - socket.io started
client connected
client connected
4Z0bYHzfWCEFzbbe4WUK disconnected
e_uSvxhSLbLAC9-F4WUL disconnected
client connected
bKDy90gsrWWTRJDD4WUM disconnected
client connected
RJ5qqCL2wfmXbd7U4WUN disconnected
client connected
wjN5Sqx4rucRtWL_4WUO disconnected