在 socket.io 上关闭套接字服务器端? [英] Closing a socket server side on socket.io?

查看:32
本文介绍了在 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.

  1. 我如何为服务器提供保护,以便阻止/删除/禁止未经授权的人(未通过网站连接的人).

  1. 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();

您也许可以检查引用标头.查看Socket.io 安全问题了解更多信息.

You might be able to check the referer header. Look at Socket.io Security Issues for more info.

这篇关于在 socket.io 上关闭套接字服务器端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆