title: Java app hangs on in.hasNext();
body: <p>I am working on Battleship swing app that communicates through sockets. </p>
  
  <pre><code>private ServerSocket server;
  private Socket connection;
  private PrintWriter out;
  private Scanner in;
  </code></pre>
  
  <p>I make a connection and setup output and input streams</p>
  
  <pre><code>out = new PrintWriter(connection.getOutputStream(), true);
  in = new Scanner(connection.getInputStream());
  </code></pre>
  
  <p>Then user clicks on field that he thinks there is a ship, and coordinates get sent </p>
  
  <pre><code>public void sendXY(String cord)
  {
      out.print(cord);
  }
  </code></pre>
  
  <p>Then the method gets called that waits for opponents app to respond if there is a ship or not (true|false).</p>
  
  <pre><code>public void readHit()
  {
      boolean k = true;
      while(k)
      {
          if(in.hasNext()) //&lt;--app hangs at this line
          {
              Fields.hit = in.nextBoolean();
              k = false;  
          }
      }
  }
  </code></pre>
  
  <p>But when I test this, my app hangs at first call to in.hasNext().</p>