title: Emscripten -> websockify -> raw tcp unexpected hung up
body: <p>I have problem with connect to raw TCP server form compiled web-application with emscripten.
  When I connect from deskopt version of app all works great.</p>
  
  <p>On my VPS I download, compiled and run websockify by:</p>
  
  <pre><code>./websockify 0.0.0.0:1235 127.0.0.1:1234
  </code></pre>
  
  <p>next I compile and run my server,
  code: <a href="http://pastebin.com/KiehDrvk" rel="nofollow">http://pastebin.com/KiehDrvk</a>  (from BeeJ networking)</p>
  
  <p>My client code is very simple(only for tests purpose),
  bit of code:</p>
  
  <pre><code>    TCPsocket sock;
      struct sockaddr_in sock_addr;
  
      /* Allocate a TCP socket structure */
      sock = (TCPsocket)malloc(sizeof(*sock));
      if ( sock == NULL ) {
          SDLNet_SetError("Out of memory");
          goto error_return;
      }
  
      /* Open the socket */
      sock-&gt;channel = socket(AF_INET, SOCK_STREAM, 0);
      if ( sock-&gt;channel == INVALID_SOCKET ) {
          SDLNet_SetError("Couldn't create socket");
          goto error_return;
      }
      /* Connect to remote, or bind locally, as appropriate */ 
      if ( (ip-&gt;host != INADDR_NONE) &amp;&amp; (ip-&gt;host != INADDR_ANY) ) {
  
      // #########  Connecting to remote
  
          memset(&amp;sock_addr, 0, sizeof(sock_addr));
          sock_addr.sin_family = AF_INET;
          sock_addr.sin_addr.s_addr = ip-&gt;host;
          sock_addr.sin_port = ip-&gt;port;
  
          /* Connect to the remote host */
          if ( connect(sock-&gt;channel, (struct sockaddr *)&amp;sock_addr, sizeof(sock_addr)) == SOCKET_ERROR &amp;&amp; errno != EINPROGRESS ) {
              SDLNet_SetError("Couldn't connect to remote host");
              goto error_return;
          }
          while (1);
      }
  </code></pre>
  
  <p>So when I run this on desktop, client connect to server and wait as I expected.</p>
  
  <p><strong>Server Terminal Return:</strong></p>
  
  <pre><code>selectserver: new connection from 91.211.105.49 on socket 5
  </code></pre>
  
  <p><strong>Websockify Terminal Return:</strong></p>
  
  <pre><code>None because is from desktop
  </code></pre>
  
  <p>But when I try connect form web version, client connect and suddenly disconnect:</p>
  
  <p><strong>Server Terminal Return:</strong></p>
  
  <pre><code>selectserver: new connection from 127.0.0.1 on socket 6
  selectserver: socket 6 hung up
  hung up: Success
  </code></pre>
  
  <p><strong>Websockify Terminal Return:</strong></p>
  
  <pre><code>  1: got client connection from 91.211.105.49
    1: forking handler process
    1: using plain (not SSL) socket
    1: using protocol HyBi/IETF 6455 13
    1: connecting to: 127.0.0.1:1234
    1: client closed connection
    1: handler exit
  </code></pre>
  
  <p>Someone have any idea ?</p>