title: Receiving and using a console input while connected to server
body: <p>I have used both a reader object and a scanner but while this client is connected to a simple socket server and they are both running, I cannot take an input from the user in the console and pass it to the server. pressing enter simply skips a line, scanner.nextLine() seems to capture nothing or something is going wrong when passing a variable to the output streamer.</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  import java.util.Scanner;
  public class Client {
  public static void main(String[] args) {
      Socket socket = null;  
      DataOutputStream outputStream = null;
      BufferedReader reader = null;
  
      Scanner scan = new Scanner(System.in);
      String message;
  
      String host = "macbook";
      int port = 9999;
  
      //attempts to connect to given host and port
      try {
          socket = new Socket(host, port);
          outputStream = new DataOutputStream(socket.getOutputStream());
          reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));           
      } catch (UnknownHostException e) {
          System.err.println("Don't know about host: " + host +".");
      } catch (IOException e) {
          System.err.println("Couldn't get I/O for the connection to: " + host+".");
          e.printStackTrace();
      }
  
      // if everything has been initialized then write some data
      if (socket != null &amp;&amp; outputStream != null &amp;&amp; reader != null) {
          try {
              message=scan.nextLine();
  
              outputStream.writeBytes(message);    
              String responseLine;
              while ((responseLine = reader.readLine()) != null) {
                  System.out.println("Server: " + responseLine);
                  if (responseLine.indexOf("Ok") != -1) {
                    break;
                  }
              }
              //closes client once communication with server has ended
              outputStream.close();
              reader.close();
              socket.close();   
          } catch (UnknownHostException e) {
              System.err.println("Trying to connect to unknown host: " + e);
          } catch (IOException e) {
              System.err.println("IOException:  " + e);
          }
      }
  }           
  }
  </code></pre>