迷茫2017-04-17 16:01:31
Socket#request:Request
A getter proxy that returns the reference to the request that
originated the underlying engine.io Client. Useful for accessing
request headers such as Cookie or User-Agent.
socket.io
通过 socket.request.headers.cookie 来得到cookie
通过 socket.request.session 来得到session
io.on('connection', function(socket){
if(socket.request.session.isLogin()){
//....已登入成功 做其他事情
}
else{
socket.close();
}
});
高洛峰2017-04-17 16:01:31
I store the socket by ID separately. When logging in, emit('login',id), the server responds by updating the socket's id, and deletes it when exiting, socket.id=null, socketManager.remove('xx') .