title: Why nsIScriptableInputStream is not working?
body: <p>I'm working on firefox extension which will communicate with java through Socket.</p>
  
  <p>Here is my java code </p>
  
  <pre><code>      Socket clientSocket = new Socket("localhost", 8888);
        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
        String messageToServer="Success" ;
        out.write(messageToServer);
  </code></pre>
  
  <p>Here is my javascript</p>
  
  <pre><code>var reader = {
              onInputStreamReady : function(input) {
                  var sin = Components.classes["@mozilla.org/scriptableinputstream;1"]
                              .createInstance(Ci.nsIScriptableInputStream);
                  sin.init(input);
                  var request = '';
                  try
                  {
                    while (true)
                    {
                      var chunk = sin.read(512);
                      alert(chunk.length);
                      if (chunk.length == 0)
                        break;
                      alert(chunk);
                      request=request+chunk;
                    }
                    alert("Received"+request);
                  }
                  catch (e)
                  {
                    alert("Error: failed reading from stream:\n" + e + "\n");
                  }
              } 
          } 
      var listener = {
          onSocketAccepted: function(serverSocket, transport) {
              addSpan("Accepted connection on " + transport.host + ":" + transport.port);
              var input = transport.openInputStream(0, 0, 0).QueryInterface(Ci.nsIAsyncInputStream);
              var output = transport.openOutputStream(Ci.nsITransport.OPEN_BLOCKING, 0, 0);
              var tm = Cc["@mozilla.org/thread-manager;1"].getService();
              input.asyncWait(reader,0,0,tm.mainThread);
  
          }
      }
  </code></pre>
  
  <p>But the Javascript doesn't receive anything. I see the same problem in the <a href="https://stackoverflow.com/questions/7158656/data-transfer-using-sockets-java-firefox-extension">link</a>. What to do to make this work?</p>