title: Java: Prevent Socket DataInputStream from throwing EOFException
body: <p>My client/server application currently keeps opening and closing new connections every time it wants to send/receive data.  I'm trying to change it so it will have one persistent connection.  </p>
  
  <p>The problem I'm having is the socket's DataInputStream on the server keeps throwing EOFException's when I just want it to block until it receives the next batch of data.</p>
  
  <p>I thought about just simply writing the server like this...</p>
  
  <pre><code>while socket is open {
      while at socket's DataInputStream's EOF {
          wait a second
      }
      //If we're here, then we have some data
      do stuff
  }
  </code></pre>
  
  <p>... but this is extremely ugly and not the proper way to block until some data is received.</p>
  
  <p>Is there a cleaner way to tell the socket to block until there's some data to read?  I've tried read() and readFully(), but neither work.</p>