Reading a socket from JS?

Dean Edmonds <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xpcom
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.