title: Proxy server does not get response from server
body: <p>This is my first time making a web server. I want to create a proxy server. For now, I'm setting the server to "www.google.com" and not doing any parsing of HTTP requests. </p>
  
  <p>I run ProxyServer on command line, then I call the server using "telnet server_name 5000" on another command line window, followed by "GET / HTTP/1.1". </p>
  
  <p>Everything works until the while loop that handles the server's response. Nothing gets printed out. Why is that so? </p>
  
  <p>All help appreciated.</p>
  
  <pre><code>import java.net.*;
  import java.io.*;
  
  public class ProxyServer {
      public static void main(String[] args) throws IOException {
  
      int proxyServerPortNumber = 5000;
      String hostName = "www.google.com";
      int portNumber = 80;
  
  
      try {
          // SERVER
          // Open socket connection and bind it to proxyServerPortNumber
          ServerSocket serverSocket =
              new ServerSocket(proxyServerPortNumber);
  
          // Listen and accept request
          Socket clientSocket = serverSocket.accept();     
          System.out.println("client request accepted");
  
          // send to client socket
          PrintWriter sendToClient =
              new PrintWriter(clientSocket.getOutputStream(), true);     
  
          // get from client socket           
          BufferedReader getFromClient = new BufferedReader(
              new InputStreamReader(clientSocket.getInputStream()));
  
          // CLIENT
          // open socket connection
          Socket echoSocket = new Socket(hostName, portNumber);
  
          // send to server
          PrintWriter out =
              new PrintWriter(echoSocket.getOutputStream(), true);
  
          // get from server
          BufferedReader in =
              new BufferedReader(
                  new InputStreamReader(echoSocket.getInputStream()));
  
  
          String clientRequest;
          // clientRequest = "GET / HTTP/1.1\r\n\r\n";
          while ((clientRequest = getFromClient.readLine()) != null) {
              System.out.println("in while loop");
              System.out.println(clientRequest);
  
              out.println(clientRequest); // send to server
              System.out.println("sent to server");
  
              //Get response from server
               String response;
               while ((response = in.readLine()) != null) // no response why?
              {
                  sendToClient.println("echo: " + response);
                  System.out.println("echo:" + response);
              }    
          } // end while loop
  
  
      } catch (IOException e) {
          System.out.println("Exception caught when trying to listen on port "
              + portNumber + " or listening for a connection");
          System.out.println(e.getMessage());
      }
  
  
  }
  }
  </code></pre>