4
我需要连接到我的Firefox扩展中的远程服务器(监听端口9442)。我正在使用nsISocketTransportService
,我的问题是如何收听dataAvailable
事件?我搜索mozilla文档,但可以找到有用的东西。我的问题是,当我使用nsISocketTransportService.createTransport()
连接到远程服务器时,如何监听数据?有没有其他方式连接到远程TCP服务器?如何使用Firefox扩展中的nsISocketTransportService连接到远程服务器?
var socket = Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService)
.createTransport(null, 0, host, port, null);
var poolOutputStream = socket.openOutputStream(0, 0, 0);
var helloMessage = JSON.stringify({type: 'hello', clientID: currentClientID});
poolOutputStream.write(helloMessage, helloMessage.length);
var poolRawInputStream = socket.openInputStream(0, 0, 0);
var poolInputStream = Components.classes ["@mozilla.org/scriptableinputstream;1"]
.createInstance(Components.interfaces.nsIScriptableInputStream)
.init(poolRawInputStream);
'nsIInputStreamPump'是正是我需要的,我会尽快测试你的代码,并回来的结果。谢谢弗拉基米尔 – 2012-04-17 13:17:08