title: Java Socket Server with JavaScript Client
body: <p>I put together a Java socket server and client that can send messages to each other, I want to use JavaScript as a client, but... Here is what happens when I'm hosting the Java server and load the JavaScript client.</p>
  
  <p>JavaScript:</p>
  
  <pre><code>    var connection = new WebSocket('ws://127.0.0.1:9005');
  connection.onopen = function () {
    connection.send('Ping');
  };
  </code></pre>
  
  <p>This Prints in the chrome console:</p>
  
  <blockquote>
    <p>WebSocket connection to 'ws://127.0.0.1:9005/' failed: Error during WebSocket handshake: Invalid status line
    <br>WebSocket Error [object Event]</p>
  </blockquote>
  
  <p>What I'm trying to do is send "Ping" to the Java server, but instead it sends all this stuff than disconnects...</p>
  
  <p>This prints in the Java server console:</p>
  
  <blockquote>
    <p>Bread Server running...
    <br>New Connection From: 127.0.0.1:51948
    <br>127.0.0.1:51948: GET / HTTP/1.1
    <br>127.0.0.1:51948: Host: 127.0.0.1:9005
    <br>127.0.0.1:51948: Connection: Upgrade
    <br>127.0.0.1:51948: Pragma: no-cache
    <br>127.0.0.1:51948: Cache-Control: no-cache
    <br>127.0.0.1:51948: Upgrade: websocket
    <br>127.0.0.1:51948: Origin: <a href="http://markstuff.net" rel="noreferrer">http://markstuff.net</a>
    <br>127.0.0.1:51948: Sec-WebSocket-Version: 13
    <br>127.0.0.1:51948: User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) <br>AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.103 Safari/537.36
    <br>127.0.0.1:51948: Accept-Encoding: gzip, deflate, sdch
    <br>127.0.0.1:51948: Accept-Language: en-US,en;q=0.8
    <br>127.0.0.1:51948: Sec-WebSocket-Key: D4Epyc7LwvPdfeDWG0sY2g==
    <br>127.0.0.1:51948: Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
    <br>127.0.0.1:51948: 
    <br>ERROR: Software caused connection abort: recv failed</p>
  </blockquote>
  
  <p>JavaScript Client:
  markstuff.net/socket/ - markstuff.net/socket/client.js<br>
  Java Server:
  pastebin com cdZjUWQp<br>
  Java Client:
  pastebin com efEeezcR</p>