Firefox Extension Socket Transport
- by Nathan
Hey, I'm making a firefox extension and I'm currently trying to get it to send XML data over a local socket to another application that's listening on that socket. Does anyone know what I'm doing wrong in this? Its probably something simple and I'm just having a monday. Thanks.
socketConn: function() {
var httpLoc = window.top.getBrowser().
selectedBrowser.contentWindow.location.href;
var outputData = '<?xml version="1.0"?>' +
'<site_data>' +
'<session_id></session_id>' +
'site_url>' + httpLoc + '</site_url>' +
'<mime_type></mime_type>' +
'<data_file>' + filePath + '</data_file>' +
'<capture_mode></capture_mode>' +
'</site_data>\n';
var transportService = Cc["@mozilla.org/network/socket-transport-service;1"]
.getService(Ci.nsISocketTransportService);
var transport = transportService.createTransport(["starttls"], 1,"localhost",currentPort, null);
var outstream = transport.openOutputStream(0, 0, 0);
outstream.write(outputData, outputData.length);
var stream = transport.openInputStream(0, 0, 0);
var instream = Cc["@mozilla.org/scriptableinputstream;1"]
.createInstance(Ci.nsIScriptableInputStream);
instream.init(stream);
var dataListener = {
data : "",
onStartRequest: function(request, context){},
onStopRequest: function(request, context, status){
instream.close();
outstream.close();
},
onDataAvailable: function(request, context, inputStream, offset, count){
this.data += instream.read(count);
},
};//end dataListener
var pump = Cc["@mozilla.org/network/input-stream-pump;1"]
.createInstance(Ci.nsIInputStreamPump);
pump.init(stream, -1, -1, 0, 0, false);
pump.asyncRead(dataListener, null);
}//end socketConn
Please ask questions about this if you don't understand what I'm trying to do with this.