title: Scanner.nextLine() blocks when using InputStream from Socket
body: <p>When I receive data using <code>Socket.getInputStream()</code> directly (without some kind of interface like Scanner), it doesn't block. But, when I try to use a Scanner (similar to how we receive Strings from <code>System.in</code>), it does. I was wondering the reason for this, and how the InputStream that a connected Socket supplies to you is different from the <code>InputStream in</code> in <code>System</code>.</p>
  
  <p>The Client used for testing (used for both servers)</p>
  
  <p>The code that hangs:</p>
  
  <pre><code>public class Server {
  
      public static void main(String[] args) {
          try {
              ServerSocket ss = new ServerSocket(15180);
              Socket socket = ss.accept();
  
              Scanner scanner = new Scanner(socket.getInputStream());
              //read data from client
              while(true) {
                  String data = scanner.nextLine();
                  System.out.println("Received data!");
              }
  
          }catch(IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>The code that doesn't block:</p>
  
  <pre><code>public class Server {
      public static void main(String[] args) {
          try {
              ServerSocket ss = new ServerSocket(15180);
              Socket socket = ss.accept();
  
              //read data from client
              while(true) {
                  int data = socket.getInputStream().read();
                  System.out.println("Received data!");
              }
  
          }catch(IOException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>