title: Java server program doesn't accept the input from client at second run of client
body: <p>I wrote a small client server program in Java. Server creates a <code>ServerSocket</code> on some port and keeps listening to it. <code>Client</code> sends some sample info to this server.
  When I run <code>Client</code> the first time connection is accepted by server and info is printed by server. Then <code>Client</code> program exits. When I run <code>Client</code> again, connection is accepted however, data is not printed. 
  Please check following code. </p>
  
  <p><strong>Server Program</strong></p>
  
  <pre><code>package javadaemon;
  
  import java.io.DataInputStream;
  import java.io.IOException;
  import java.net.ServerSocket;
  import java.net.Socket;
  
  public class MyDaemon {
      public static void main(String [] args) throws IOException {
              ServerSocket ss = new ServerSocket(9879);
              ss.setSoTimeout(0);
          while(true) {
              Socket s = ss.accept();
              System.out.println("socket is connected? "+s.isConnected());
              DataInputStream dis = new DataInputStream(s.getInputStream());
              System.out.println("Input stream has "+dis.available()+" bytes available");
              while(dis.available() &gt; 0) {
                  System.out.println(dis.readByte());
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Client Program</strong></p>
  
  <pre><code>package javadaemon;
  
  import java.io.*;
  import java.net.Socket;
  
  public class Client {
  public static void main(String [] args) {
      try {
          System.out.println("Connecting to " + "127.0.0.1"
                              + " on port " + 9879);
          Socket client = new Socket("127.0.0.1", 9879);
          System.out.println("Just connected to "
                      + client.getRemoteSocketAddress());
          OutputStream outToServer = client.getOutputStream();
          DataOutputStream out = new DataOutputStream(outToServer);
  
          for(int i=0; i&lt;100; i++ ) {
              out.writeUTF("Syn "+i);
          }
  
      } catch(IOException e) {
      }
  }
  }
  </code></pre>
  
  <p>Please help me in finding why next time no data is received by server.</p>