I've managed to write to a socket from JavaScript, using 
nsIOutputStream.write(), but when I try to read from it using 
nsIScriptableInputStream.read() I get an NS_ERROR_NOT_IMPLEMENTED exception.

So how do I go about reading from a socket?

My code is as follows:

 
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");

var component, iface, transport, ostream, istream, sIstream;

component = Components
        .classes["@mozilla.org/network/socket-transport-service;1"]
        .createInstance();

iface = component.QueryInterface(
        Components.interfaces.nsISocketTransportService
);

transport = iface.createTransport("mjollnir", 7070, null, 256, 2048);

ostream = transport.openOutputStream(0, -1, 0);
istream = transport.openInputStream(0, -1, 0);

component = Components
        .classes["@mozilla.org/scriptableinputstream;1"]
        .createInstance();

istream2 = component.QueryInterface(
        Components.interfaces.nsIScriptableInputStream
);

istream2.init(istream);

var str = "Hello";
ostream.write(str, str.length);

var result = istream2.read(1024);  <-- EXCEPTION HERE


Reply via email to