- 解析cookie
- 获取会话ID
- 获取会话数据
var express = require('express'); var parsecookie = express.cookieParser(); var MemoryStore = express.session.MemoryStore; var store = new MemoryStore(); app.configure(function() { app.use(express.session({ store: store, secret: '123456', key: 'sid' })); }); wss.on('connection', function(ws) { parsecookie(ws.upgradeReq, null, function(err) { var sessionID = ws.upgradeReq.cookies['sid']; store.get(sessionID, function(err, session) { // session }); }); ws.on('message', function(message) { console.log('received: %s', message); }); ws.send('something'); });
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)