Is There NsiClientSocket In Firefox Extension Javascript?
How to connect to a port from javascript in firefox extensions? I could able to open the port and listen (Server side socket), but I want the Client side socket which will connect
Solution 1:
You use nsISocketTransportService.createTransport(). Something like this should work:
var transport = Components.classes["@mozilla.org/network/socket-transport-service;1"]
.getService(Components.interfaces.nsISocketTransportService)
.createTransport(null, 0, host, port, null);
var stream = transport.openOutputStream(0, 0, 0);
var data = "test";
stream.write(data, data.length);
stream.close();
All connection events happen asynchronously so in order to listen to transport events you need to call transport.setEventSink()
:
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
transport.setEventSink({
onTransportStatus: function(transport, status, progress, progressMax)
{
...
},
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsITransportEventSync])
}, Services.tm.currentThread);
For reference: nsITransportEventSink, nsITransportEventSink status codes
Post a Comment for "Is There NsiClientSocket In Firefox Extension Javascript?"