<p>I am trying to program a small server+client in Javascript on Firefox, using XPCOM.</p>

<p>To get the HTTP message in Javascript, I am using the nsIScriptableInputStream interface.
This f**ing component through the read() method randomly cut the message and I cannot make it reliable.</p>

<p>Is anybody know a solution to get reliably the information? (I already tried a binary stream, same failure.)</p>

<p>J.</p>

[{'answer_id': 73939, 'author': 'Chouser', 'author_id': 7624, 'author_profile': 'https://Stackoverflow.com/users/7624', 'pm_score': 0, 'selected': False, 'text': '<p>If you control the protocol (that is, both the client and server) I would highly recommend using Javascript/JSON for your server-to-client messages.  The client can open a stream either via dynamically adding a &lt;script&gt; tag to the DOM.  The server can then send a stream of Javascript commands like:</p>\n\n<pre><code>receiveMsg({type:"text", content:"this is my message"});\n</code></pre>\n\n<p>Then the client just needs to define a receiveMsg function. This allows you to rely on fast browser code to parse the message and determine where the end of each message is, at which point it will call your handler for you.</p>\n\n<p>Even if you\'re working with an existing HTTP protocol and can\'t use JSON, is there some reason you can\'t use XMLHttpRequest?  I would expect it to be more stable than some poorly documented Firefox-specific XPCOM interface.</p>\n\n<p>--Chouser</p>\n'}, {'answer_id': 75825, 'author': 'Zach', 'author_id': 9128, 'author_profile': 'https://Stackoverflow.com/users/9128', 'pm_score': 1, 'selected': False, 'text': '<p>I had the same problem with unreliability... I ended up using XMLHTTPRequest, which when used from the XPCOM component can do cross site requests. The second part of the <a href="http://developer.mozilla.org/en/XMLHttpRequest" rel="nofollow noreferrer">docs</a> detail how to instantiate the XPCOM version.</p>\n\n<p>If you\'re looking to serve HTTP request I\'d take a look at the <a href="https://addons.mozilla.org/en-US/firefox/addon/3002" rel="nofollow noreferrer">POW</a> source code and the use of <a href="http://www.xulplanet.com/tutorials/mozsdk/serverpush.php" rel="nofollow noreferrer">server sockets</a>, which implements a basic HTTP server in JavaScript. Also check out <a href="http://mxr.mozilla.org/mozilla/source/netwerk/test/httpserver/httpd.js" rel="nofollow noreferrer">httpd.js</a></p>\n'}]
['https://Stackoverflow.com/questions/72958', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']