title: websocket unable to connect to android emulator
body: <p>So here's the code for my very simple WebSocket code to connect to the Android Emulator ... and it hangs.</p>
  
  <p>I can confirm I can telnet to the emulator fine. I can also Websocket to a web server ok, even though http gives the old "unexpect response code 200". I can also confirm that the readState is a constant zero.</p>
  
  <p>I can also confirm that a connection is established when the page is connected and disconnects when it's removed.</p>
  
  <p>Whilst page up:</p>
  
  <pre><code>$ netstat -a | grep 5554
    TCP    127.0.0.1:5554         eww:0                  LISTENING
    TCP    127.0.0.1:5554         eww:49516              ESTABLISHED
    TCP    127.0.0.1:5554         eww:54424              ESTABLISHED
    TCP    127.0.0.1:49516        eww:5554               ESTABLISHED
    TCP    127.0.0.1:54424        eww:5554               ESTABLISHED
  </code></pre>
  
  <p>After page removed:</p>
  
  <pre><code>$ netstat -a | grep 5554
    TCP    127.0.0.1:5554         eww:0                  LISTENING
    TCP    127.0.0.1:5554         eww:49516              ESTABLISHED
    TCP    127.0.0.1:49516        eww:5554               ESTABLISHED
    TCP    127.0.0.1:54424        eww:5554               TIME_WAIT
  </code></pre>
  
  <p>I'm using Chrome and this is all running on Windows 7. The other connection is likely to be Eclipse.</p>
  
  <p>Any thoughts?</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Telnet to Android Emulator&lt;/title&gt;
  &lt;style&gt;
      #messages {
          list-style: none;
      }
  &lt;/style&gt;
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;h1&gt;Telnet to Android Emulator&lt;/h1&gt;
  
  &lt;ul id="messages"&gt;
  &lt;/ul&gt;
  
  &lt;script&gt;
      $(document).ready(function() {
  
          function log(message) {
              $('#messages').append('&lt;li&gt;' + message + '&lt;/li&gt;');
          }
  
          var socket;
  
          if ("WebSocket" in window) {
              log("WebSocket API supported");
          } else {
              log("WebSocket API not supported");
          }
  
          function wsOpen(e) {
              log("OPEN");
          }
  
          function wsClose(e) {
              log("CLOSED");
          }
  
          function wsError(e) {
              log("ERROR " + e.data);
          }
  
          function wsMessage(e) {
              log(e.data);
          }
  
          function openSocket() {
  
              var wsuri = "ws://localhost:5554";
  
              log("connecting to " + wsuri);
  
              try {   
                  socket = new WebSocket(wsuri);
  
                  socket.onopen = wsOpen;
                  socket.onclose = wsClose;
                  socket.onerror = wsError;
                  socket.onmessage = wsMessage;
  
              } catch (exception) {
                  log('Caught ' + exception);
              }               
          }
  
          function closeSocket() {
  
              log("disconnecting");
              socket.close();
          }
  
          openSocket(); // down here for testing
      });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>