title: Connecting to a ServerSocket in Java with a Javascript client
body: <p>If I have a ServerSocket in Java, how can I connect to it through Javascript?
  This isn't a WebSocket. Here is part of my server code:</p>
  
  <pre class="lang-java prettyprint-override"><code>ServerSocket server = new ServerSocket(3000);
  Socket client = server.accept();
  BufferedWriter clientOut = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
  clientOut.write('Hello World!\n');
  clientOut.flush();
  clientOut.close();
  client.close();
  server.close();
  </code></pre>
  
  <p>When I try to use a WebSocket to connect, I get this error:</p>
  
  <blockquote>
    <p>SyntaxError: An invalid or illegal string was specified</p>
  </blockquote>
  
  <p>And this is what I use to connect:</p>
  
  <pre class="lang-js prettyprint-override"><code>socket = new WebSocket('http://localhost:3000')
  </code></pre>
  
  <p>Do note that I would also like a pure Javascript way of doing this, and I wouldn't want a Java applet hidden inside my page to send and read data through the socket.</p>