title: Make a client & server connection stable in Java
body: <p>I'm creating a Server application in Java but when client connects to a server and opens a stream, the stream come to and end the connection is lost. What I need is to keep that connection alive even when the stream has ended. Here is a code example to better explain what I'm saying:</p>
  
  <pre><code>     diSTR = new DataInputStream(Conexao.getInputStream());
       doSTR = new DataOutputStream(Conexao.getOutputStream());
       conectado = true;
       while (diSTR.available() &gt; 0)
       {
          byte[] buffer = new byte[size];
          diSTR.readFully(buffer);
          String str = new String(buffer, "UTF-8");
          log(str);
       }
  </code></pre>
  
  <p>So when <code>diSTR.available()</code> returns <code>0</code> the method returns and the connection is over, how can I solve this problem? </p>