是否有可能创建一个浏览器扩展来允许传入的请求? [英] Is it possible to create a browser extension to allow for incoming requests?

本文介绍了是否有可能创建一个浏览器扩展来允许传入的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来传入请求到浏览器。在浏览器中安装扩展是可以的。这样做的目的是允许另一台机器连接到扩展来控制一个游戏,而不需要中间服务器。

这是可行的吗?是否有可能使Chrome或Firefox扩展打开一个端口,以允许传入的请求?

服务器套接字。对于Chrome,答案是否,Chrome扩展程序只能打开客户端连接。另一方面,Firefox扩展可以使用 nsIServerSocket 界面监听端口上的传入TCP连接。如果您使用附加SDK ,则需要使用 chrome 。就像这样:
$ b

  var {Cc,Ci} = require(chrome); 
var socket = Cc [@ mozilla.org/network/server-socket;1]
.createInstance(Ci.nsIServerSocket);
socket.init(12345,false,-1);
socket.asyncListen({
onSocketAccepted:function(socket,transport)
{
...
},
onStopListening:function(socket,status )
{
}
});


I am looking to figure out a way to make incoming request to a browser. Installing an extension in the browser is OK. The goal of this is to allow another machine to connect to the extension to control a game without needing an intermediary server.

Is this feasible? Is it possible to make a Chrome or Firefox extension open a port to allow for incoming request?

解决方案

What you are asking for are server sockets. For Chrome the answer is "no", Chrome extensions can only open client connections. Firefox extensions on the other hand can use nsIServerSocket interface to listen for incoming TCP connections on a port. If you use the Add-on SDK you would need to use the chrome package. Something like this:

var {Cc, Ci} = require("chrome");
var socket = Cc["@mozilla.org/network/server-socket;1"]
               .createInstance(Ci.nsIServerSocket);
socket.init(12345, false, -1);
socket.asyncListen({
  onSocketAccepted: function(socket, transport)
  {
    ...
  },
  onStopListening: function(socket, status)
  {
  }
});

这篇关于是否有可能创建一个浏览器扩展来允许传入的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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