title: A Simple Http Server with Java/Socket?
body: <p>I am currently creating a small HTTP server that returns a static page <code>&lt;p&gt;Hello!&lt;/p&gt;</code>...
  I tried with sockets with Java:</p>
  
  <pre><code>  public static void main(String[] args) throws Exception {
  
          // création de la socket
          int port = 1989;
          ServerSocket serverSocket = new ServerSocket(port);
          System.err.println("Serveur lancé sur le port : " + port);
  
          // repeatedly wait for connections, and process
          while (true) {
  
              // on reste bloqué sur l'attente d'une demande client
              Socket clientSocket = serverSocket.accept();
              System.err.println("Nouveau client connecté");
  
              // on ouvre un flux de converation
  
             BufferedReader in = new BufferedReader(
                             new InputStreamReader(clientSocket.getInputStream())
                            ); 
              PrintWriter out = new PrintWriter(
                           new BufferedWriter(
                              new OutputStreamWriter(clientSocket.getOutputStream())), 
                           true);   
  
              // chaque fois qu'une donnée est lue sur le réseau on la renvoi sur le flux d'écriture.
              // la donnée lue est donc retournée exactement au même client.
              String s;
              while ((s = in.readLine()) != null) {
                  System.out.println(s);
  
  
         out.write("HTTP/1.0 200 OK\r\n");
         out.write("Date: Fri, 31 Dec 1999 23:59:59 GMT\r\n");
         out.write("Server: Apache/0.8.4\r\n");
         out.write("Content-Type: text/html\r\n");
         out.write("Content-Length: 59\r\n");
         out.write("Expires: Sat, 01 Jan 2000 00:59:59 GMT\r\n");
         out.write("Last-modified: Fri, 09 Aug 1996 14:21:40 GMT\r\n");
         out.write("\r\n");
         out.write("&lt;TITLE&gt;Exemple&lt;/TITLE&gt;");
         out.write("&lt;P&gt;Ceci est une page d'exemple.&lt;/P&gt;");
    }
  
              // on ferme les flux.
              System.err.println("Connexion avec le client terminée");
              out.close();
              in.close();
              clientSocket.close();
          }
      }
  </code></pre>
  
  <p>this code does not contain any errors and I got a response from the browser like this:</p>
  
  <pre><code>GET / HTTP/1.1
  Host: localhost:1989
  Connection: keep-alive
  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5 Comodo_Dragon/19.0.3.0
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
  Accept-Encoding: gzip,deflate,sdch
  Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
  </code></pre>
  
  <p>But my problem is that I get no page at the Browser?
  Any help please?</p>
  
  <p>PS: I already read this article: <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol" rel="noreferrer">http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol</a> , (im sorry for the french language...)</p>