本文介绍了退出后销毁握手。 socket.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,我正在尝试在一个应用程序中建立聊天。我想知道的是,当用户注销网站时,如何还销毁与该会话相关联的socket.io握手,以便用户在注销时不能从另一个标签发送消息。如果有任何帮助,我使用expressjs。
解决方案
如果有人找到这个并想知道我已经弄清楚了。
您可以访问套接字断开连接功能。我有对象的用户ID和他们的套接字ID,所以当有人退出我打电话
app.get(/ logout函数(req,res){
pre>
//做其他注销东西
sockets.disconnectUser(req.session.user_id);
}
//断开用户函数
sockets.disconnectUser = function(user_id){
sockets.socket(users [user_id])。disconnect();
}
Hello I am trying to build chat into an application. What I am wondering is when the user logs out of the website how do I also destroy the socket.io handshake associated with that session so the user cannot send messages from say another tab when he is logged out.
I am using expressjs if that is any help.
解决方案Well in case anyone ever find this and wants to know I did figure it out. You can access the sockets disconnect function. I had object of users ids and their socket id so when someone logged out I called
app.get("/logout", function(req,res){ //do other logging out stuff sockets.disconnectUser(req.session.user_id); } // Disconnect User function sockets.disconnectUser = function(user_id){ sockets.socket(users[user_id]).disconnect(); }
这篇关于退出后销毁握手。 socket.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!