通过 JavaScript 访问 TCP 连接

发布于 2024-12-11 09:16:17 字数 147 浏览 0 评论 0原文

我的目标是识别 firefox 插件中的 TCP 连接。

为此,我需要为每个连接设置一个唯一的 ID。我的问题是,是否可能并且有人知道如何从 HTTP 请求访问 TCP 连接的对象?然后我可以为其设置一个唯一的 ID,并且每个请求/响应对都将唯一地设置为一个连接。

My goal is it to identify the TCP-Connections in a firefox-plugin.

For that I need to set a unique ID to every connection. My question is, if its possible and someone knows how to get access to the Object of the TCP-Connection from a HTTP-Request? Then I could set a unique ID to it and every request/response pair would be uniquely set to a connection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

两人的回忆 2024-12-18 09:16:17

虽然我不知道您问题的直接答案,但我建议您查看源代码Firebug,它似乎至少可以访问网络堆栈的HTTP请求级别,甚至可能更低。

希望这有帮助,祝你好运!

While I don't know the direct answer to your question, I would suggest taking a look at the source code for Firebug, it seems to have access to at least the HTTP request level of the network stack, maybe even lower.

Hope this helps, good luck!

╰◇生如夏花灿烂 2024-12-18 09:16:17

假设您正在谈论客户端 JavaScript,有一些项目可以帮助您实现此功能。

  1. http://code.google.com/p/jssockets/ [需要闪存]
  2. < a href="http://socket.io/" rel="nofollow">http://socket.io/

希望有帮助。

Assuming that you are talking about client side javascript, there are some projects which will help you to achieve this functionality.

  1. http://code.google.com/p/jssockets/ [flash is required]
  2. http://socket.io/

Hope it helps.

叫思念不要吵 2024-12-18 09:16:17

来自 MDN:如何监控 HTTP 活动

这是他们的示例代码

// Define a reference to the interface
var nsIHttpActivityObserver = Components.interfaces.nsIHttpActivityObserver;

var httpObserver =
{
    observeActivity: function(aHttpChannel, aActivityType, aActivitySubtype, aTimestamp, aExtraSizeData, aExtraStringData)
    {
      if (aActivityType == nsIHttpActivityObserver.ACTIVITY_TYPE_HTTP_TRANSACTION) {
        switch(aActivitySubtype) {
          case nsIHttpActivityObserver.ACTIVITY_SUBTYPE_RESPONSE_HEADER:
            // received response header
            break;
          case nsIHttpActivityObserver.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
            // received complete HTTP response
            break;
        }
      }
    }
};

var activityDistributor = 
    Components.classes["@mozilla.org/network/http-activity-distributor;1"]
    .getService(Components.interfaces.nsIHttpActivityDistributor);
activityDistributor.addObserver(httpObserver);

From MDN: How to monitor HTTP activity

Here's their sample code

// Define a reference to the interface
var nsIHttpActivityObserver = Components.interfaces.nsIHttpActivityObserver;

var httpObserver =
{
    observeActivity: function(aHttpChannel, aActivityType, aActivitySubtype, aTimestamp, aExtraSizeData, aExtraStringData)
    {
      if (aActivityType == nsIHttpActivityObserver.ACTIVITY_TYPE_HTTP_TRANSACTION) {
        switch(aActivitySubtype) {
          case nsIHttpActivityObserver.ACTIVITY_SUBTYPE_RESPONSE_HEADER:
            // received response header
            break;
          case nsIHttpActivityObserver.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
            // received complete HTTP response
            break;
        }
      }
    }
};

var activityDistributor = 
    Components.classes["@mozilla.org/network/http-activity-distributor;1"]
    .getService(Components.interfaces.nsIHttpActivityDistributor);
activityDistributor.addObserver(httpObserver);
記憶穿過時間隧道 2024-12-18 09:16:17

我在我自己的 ff 插件中做了一些非常类似的事情。我假设您需要对与连接关联的 nsiHttpChannel 的引用。但是,我不确定您是否可以向其添加属性(并让它们保留),因为它可能由本机代码支持,我不确定哪种方式。但是您可以将nsiHttpChannel存储在其他地方并以这种方式保留一个ID。

这是我用来监视插件中的 http 流量的一些简化代码,它应该可以解决您的问题。

var Cc = Components.classes;
var Ci = Components.interfaces;

var MyHttpObserver = {
    // must be exposed so that the ObserverService can register itself
    observe: function(subject, topic, data) {
        subject.QueryInterface(Ci.nsIHttpChannel);
        if( topic === "http-on-modify-request" ){
            // store 'subject' somewhere
        } else if( topic === "http-on-examine-response" ){
            // look up 'subject' it will be the same reference as before
        }
    },

    register: function() {
        var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
        observerService.addObserver(this, "http-on-modify-request", false);
        observerService.addObserver(this, "http-on-examine-response", false);
    },

    unregister: function() {
        var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
        observerService.removeObserver(this, "http-on-modify-request");
        observerService.removeObserver(this, "http-on-examine-response");
    },

    QueryInterface: function (aIID) {
        if (aIID.equals(Ci.nsIObserver) || aIID.equals(Ci.nsISupports) ){
            return this;
        }
        throw Components.results.NS_NOINTERFACE;
    }
};

I do something very similar in my own ff addon. I'm assuming that you want a reference to the nsiHttpChannel associated with the connection. However, I'm not sure you can just add properties to it (and have them persist), since its probably backed by native code, I'm not sure either way. But you can store the nsiHttpChannel elsewhere and keep an id on it that way.

Here's some simplified code that I use to monitor http traffic in my addon, which should solve your problem.

var Cc = Components.classes;
var Ci = Components.interfaces;

var MyHttpObserver = {
    // must be exposed so that the ObserverService can register itself
    observe: function(subject, topic, data) {
        subject.QueryInterface(Ci.nsIHttpChannel);
        if( topic === "http-on-modify-request" ){
            // store 'subject' somewhere
        } else if( topic === "http-on-examine-response" ){
            // look up 'subject' it will be the same reference as before
        }
    },

    register: function() {
        var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
        observerService.addObserver(this, "http-on-modify-request", false);
        observerService.addObserver(this, "http-on-examine-response", false);
    },

    unregister: function() {
        var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
        observerService.removeObserver(this, "http-on-modify-request");
        observerService.removeObserver(this, "http-on-examine-response");
    },

    QueryInterface: function (aIID) {
        if (aIID.equals(Ci.nsIObserver) || aIID.equals(Ci.nsISupports) ){
            return this;
        }
        throw Components.results.NS_NOINTERFACE;
    }
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文