title: Javascript Sockets (failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET)
body: <p>I am trying to create a simple program to send a message to a socket in plain text.  The sender is a webpage in javascript using websocket and the server is a C program.  I don't have any control over the C code but I have been assured by the codes owners that I can use simple javascript to send the message. My code is as follows:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script type="text/javascript"&gt;
              //initialize the websocket ws
              var ws; 
              //Open the socket connection
              function openSock() {
                  //test for Websocket compatibility in the browser
                  if ("WebSocket" in window) { 
                      // log socket attempt
                      console.log("Attempting to open socket!");
                      //open web socket ws
                      ws = new WebSocket("ws://192.168.6.222:11000/echo");
                  } else { // else the browser doesn't support WebSocket
                      //Websocket is not supported
                      alert("APS NOT supported by your Browser!");
                  }
              }
              //send the command to socket ws
              function sendCommand() { 
                  console.log("Attempting to Send Message");
                  ws.send("your message here");
              }
              //close the socket ws
              function closeSock() {
                  console.log("Closing Socket");
                  // close socket ws
                  ws.close();
              }
  
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div id="sse"&gt;
              &lt;a href="javascript:openSock()"&gt;&lt;input type=submit value="open"&gt;&lt;/a&gt;
              &lt;a href="javascript:sendCommand()"&gt;&lt;input type=submit value="send"&gt;&lt;/a&gt;
              &lt;a href="javascript:closeSock()"&gt;&lt;input type=submit value="close"&gt;&lt;/a&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>When I click the connect button I get this error:</p>
  
  <blockquote>
    <p>WebSocket connection to 'ws://192.168.6.222:11000/echo' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET</p>
  </blockquote>
  
  <p>I have checked the firewall and the port seems to be open.  After spending a fair amount of time troubleshooting the server (making sure it is running and on the network, etc.) I am wondering if I did something wrong with this client side code.  </p>
  
  <p>From my limited knowledge and the reading I have done this looks correct but any help is welcome.</p>