title: HTTP Client with Java sockets
body: <p>i try to open a TCP Socket in Java and sent a GET request to a server (www.abc.net.au) and print the response to the console.</p>
  
  <p>Client code:</p>
  
  <pre><code>import java.util.Scanner;
  
  import java.net.InetAddress;
  import java.net.SocketAddress;
  import java.net.InetSocketAddress;
  import java.net.Socket;
  
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  
  public class Client {
      public static void main(String[] args) throws Exception{
  
          Scanner sc;
          String addressString;
          int port =80;
          int timeoutMs = 30000;
          String temp;
  
          //Read address from commandline
          sc =new Scanner(System.in);
          System.out.print("Adresse: ");
          addressString = sc.next();
          sc.close();
          //Open socket
          InetAddress addr = InetAddress.getByName(addressString);
          SocketAddress sockaddr = new InetSocketAddress(addr, port);
          Socket socket = new Socket();
  
          //Connection timeout
          socket.connect(sockaddr,timeoutMs);
  
          System.out.println( socket.getPort() +"\n");
  
          //Define input/output
          BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
          PrintWriter pw = new PrintWriter(socket.getOutputStream(), true);
  
          //Send GET request
          pw.print("GET / HTTP/1.1\r\n");
          pw.print("Host: "+ addressString +"\r\n\r\n");
          while((temp=br.readLine())!=null){
              System.out.println(temp);
  
          }
          //Close Input/Output and Socket
          pw.close();
          br.close();
          socket.close();
      }
  }
  </code></pre>
  
  <p>The code seems to work till it reaches the while and afterwards i get:</p>
  
  <pre><code>HTTP/1.0 408 Request Time-out
  Server: AkamaiGHost
  Mime-Version: 1.0
  Date: Sun, 07 Oct 2018 15:36:40 GMT
  Content-Type: text/html
  Content-Length: 218
  Expires: Sun, 07 Oct 2018 15:36:40 GMT
  
  &lt;HTML&gt;&lt;HEAD&gt;
  &lt;TITLE&gt;Request Timeout&lt;/TITLE&gt;
  &lt;/HEAD&gt;&lt;BODY&gt;
  &lt;H1&gt;Request Timeout&lt;/H1&gt;
  The server timed out while waiting for the browser's request.&lt;P&gt;
  Reference&amp;#32;&amp;#35;2&amp;#46;3d5b6068&amp;#46;1538926600&amp;#46;0
  &lt;/BODY&gt;&lt;/HTML&gt;
  
  Process finished with exit code 0
  </code></pre>
  
  <p>I don't understand what causes the problem, already looked for answers on stackoverflow, java2s and a book i got at home. Trying other pages often ends just with:</p>
  
  <pre><code>Process finished with exit code 0
  </code></pre>
  
  <p>and nothing else.</p>
  
  <p>Any idea what's missing/incorrect with my request?</p>
  
  <p>Appriciate every hint.</p>