title: TCP Server response timeout
body: <p>I have been tasked with getting a simple TCP Client to timeout. The client works as expected, however I cannot seem to get the client to timeout when the client does not receive an input for 3 seconds or more.
  I have a basic understanding of SO_TIMEOUT, but can't get it to work here.
  Please help</p>
  
  <p>Here is my code:
  <strong>TCPClient</strong></p>
  
  <pre><code>private static final String host = "localhost";
      private static final int serverPort = 22003;
  
      public static void main(String[] args) throws Exception
      {
  
          try
          {
              System.out.println("You are connected to the TCPCLient;" + "\n" + "Please enter a message:");
              BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
              @SuppressWarnings("resource")
              Socket client = new Socket(host, serverPort);
              client.setSoTimeout(3000);
              while(true)
              {
                  DataOutputStream outToServer = new DataOutputStream(client.getOutputStream());
                  BufferedReader inFromServer = new BufferedReader(new InputStreamReader(client.getInputStream()));
                  String input = inFromUser.readLine();
                  outToServer.writeBytes(input + "\n");
                  String modedInput = inFromServer.readLine();
                  System.out.println("You Sent: " + modedInput);
                  try
                  {
                      Thread.sleep(2000);
                  }
                  catch(InterruptedException e)
                  {
                      System.out.println("Slept-in");
                      e.getStackTrace();
                  }
              }
          }
          catch(SocketTimeoutException e)
          {
              System.out.println("Timed Out Waiting for a Response from the Server");
          }
      }
  </code></pre>