websocket - node.js express使用socket-io時,要如何做帳號驗證?
巴扎黑
巴扎黑 2017-04-17 15:59:31
0
2
633
巴扎黑
巴扎黑

reply all(2)
迷茫

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();
    }
});
小葫芦

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') .

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template