для работы с сокетами вам нужен не только поток сценариев, но и:
1.nsiTransportService
2.nsIScriptableInputStream
3.nsIInputStreamPump
выможете использовать этот код:
this.transportService = Components.classes["@mozilla.org/network/socket-transport-service;1"].
getService(Components.interfaces.nsISocketTransportService);
this.scriptablestream = Components.classes["@mozilla.org/scriptableinputstream;1"].
createInstance(Components.interfaces.nsIScriptableInputStream);
this.pump = Components.classes["@mozilla.org/network/input-stream-pump;1"].
createInstance(Components.interfaces.nsIInputStreamPump);
this.transport = this.transportService.createTransport(null, 0, server, port, null);
this.outstream = this.transport.openOutputStream(1, 0, 0);
this.outputData = "";
//this is where the connection is actually opens.
this.outstream.write(this.outputData, this.outputData.length);
this.outstream.flush();
this.stream = this.transport.openInputStream(0, 0, 0);
this.scriptablestream.init(this.stream);
var dataListener = {
data: "",
onStartRequest: function (request, context) {
//here is the event for connection established
},
onStopRequest: function (request, context, status) {
// here is the event if connection lost
},
onDataAvailable: function (request, context, inputStream, offset, count) {
// here is where you recive input from server
var response = scriptStream.read(count);
};
this.pump.init(this.stream, -1, -1, 0, 0, false);
this.pump.asyncRead(dataListener, null);
//to write to stream
outstream.write(data, data.length);
outstream.flush();
надеюсь, это поможет вам.о, кстати, по моему опыту, порядок кода имеет решающее значение, но не стесняйтесь доказать, что я работаю: -).