title: What is the proper way to listen to HTTP requests?
body: <p>I've written a very simple, rather low level HTTP (well, part of HTTP) server as an exercise to get more familiar with this whole web thing I've been avoiding all the time. It works reasonably well for a first attempt (not so much that I would recommend anyone to actually use it, but it does what I tell it to). Now the problem is that the GET operation fails a lot (refreshing helps, but it's not very nice - details below), I assume this is because of the way I read requests (I am fairly certain my routes work):</p>
  
  <pre><code>void start()
  {
      //...
      try(ServerSocket webSock = new ServerSocket(47000) {
      //...
          while(running) {
             try {
                 Socket sock = webSock.accept();
                 //read/write from/to sock 
             }
             //...
             Thread.sleep(10);
          }
      } 
  }
  </code></pre>
  
  <p>(full code here: <a href="http://pastebin.com/5B1ZuusH" rel="noreferrer">http://pastebin.com/5B1ZuusH</a> )</p>
  
  <p>I am not sure exactly <em>what</em> I'm doing wrong though.</p>
  
  <p>I do get the error:</p>
  
  <pre><code>This webpage is not available
  The webpage at http://localhost:47000/ might be temporarily down or it may have moved permanently to a new web address.
  Error 15 (net::ERR_SOCKET_NOT_CONNECTED): Unknown error.
  </code></pre>
  
  <p>quite a bit (entire page doesn't load), sometimes scripts or images don't load either. If required, I could post the entire code, but the rest is mostly boilerplate.</p>