关闭socket.io上的套接字服务器端? [英] Closing a socket server side on socket.io?
问题描述
我很确定这是一个简单的问题,但我不知道socket.io文档在哪里以及 http://labs.learnboost.com/socket.io/ 没有真正的帮助。
I'm pretty sure this is a simple question, but I have no idea where the socket.io docs are and the one at http://labs.learnboost.com/socket.io/ don't really help.
所以假设我有一个socket.io http服务器和写一个网站连接到它。
So let's say I have a socket.io http server and written a website to connect to it.
-
如何为服务器提供保护,以便未经授权的人(将被阻止/删除/禁止。
How do I provide protection to the server so that unauthorized people(people who connected not through the website) will be blocked/dropped/banned.
如何在服务器端结束套接字连接?所以如果我有
How do I end a socket connection on the server side? So If I have
io.sockets.on('connection', function (socket) {
socket.on('end', function() {
var i = global_sockets_list.indexOf(socket);
global_sockets_list.splice(i, 1);
});
socket.emit('end'); // Doesn't work, just sends data
socket.end(); //error
});
如何结束套接字连接? (上面的连接然后断开连接用于测试)
How do I end a socket connection? (The connect then disconnect above is for testing)
推荐答案
尝试呼叫:
socket.disconnect('unauthorized');
或
socket.close();
编辑:您可以检查referer标头。有关详细信息,请参阅 Socket.io安全问题。
You might be able to check the referer header. Look at Socket.io Security Issues for more info.
这篇关于关闭socket.io上的套接字服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!