6

我目前正在开发一个 Firefox 插件,它是一个使用 TCP 套接字连接到服务器的客户端。

在我的小测试中,一切正常,客户端(ff 插件)连接到服务器(用 java 设计)并发送一条消息,但在那之后 firefox 正在关闭套接字。

我知道我在服务器端的代码不是问题,因为我可以与其他客户端(用 java 和 C++ 设计)连接,而且它们从不关闭连接。

我认为问题在于Firefox在没有引用它之后破坏了套接字对象,因此关闭了连接。

无论如何,这是我的代码:

const {Cc,Ci} = require("chrome");

var host="192.168.1.100";
var port=9001;
var transport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
                          .getService(Components.interfaces.nsISocketTransportService)
                          .createTransport(null, 0, host, port, null);

var inputStream = transport.openInputStream(0, 0, 0);
var inputInterface = Components.classes["@mozilla.org/binaryinputstream;1"].createInstance(Components.interfaces.nsIBinaryInputStream);
inputInterface.setInputStream(inputStream);

var outputStream = transport.openOutputStream(0, 0, 0);
var outputInterface = Components.classes["@mozilla.org/binaryoutputstream;1"].createInstance(Components.interfaces.nsIBinaryOutputStream);
outputInterface.setOutputStream(outputStream); 

var msg="some message";
outputInterface.writeUtf8Z(msg); 

我正在使用 firefox 7,并且正在使用 firefox 附加组件 SDK 构建附加组件。

关于如何保持套接字活动的任何想法,以供进一步阅读?

谢谢

4

1 回答 1

0

Do you need build the new implementation with [1] WebRTC or your own native libraries with [2] ctypes.

[1] https://developer.mozilla.org/en-US/docs/Web/Guide/API/WebRTC

[2] https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes

XPCOM and NPAPI will deprecated soon.

于 2015-04-07T07:04:58.460 回答