title: In java network programming, is there a way to keep the Server side open even when the Client side shuts down?
body: <p>Suppose that we have a simple Echo client/server pair in Java. As I understand it, once one side of the socket breaks then the whole connection is gone. </p>
  
  <p>But what if I want a Server that can always stay alive, even if the client side dies.  I want to be able to resume a broken connection. </p>
  
  <p>Echo Server :</p>
  
  <pre><code>import java.net.Socket;
  import java.net.ServerSocket;
  
  public class EchoServer {
  
      public static void main(String[] args) throws Exception {
  
          // create socket
          int port = 4444;
          ServerSocket serverSocket = new ServerSocket(port);
          System.err.println("Started server on port " + port);
  
          // repeatedly wait for connections, and process
          while (true) {
  
              // a "blocking" call which waits until a connection is requested
              Socket clientSocket = serverSocket.accept();
              System.err.println("Accepted connection from client");
  
              // open up IO streams
              In  in  = new In (clientSocket);
              Out out = new Out(clientSocket);
  
              // waits for data and reads it in until connection dies
              // readLine() blocks until the server receives a new line from client
              String s;
              while ((s = in.readLine()) != null) {
                  out.println(s);
              }
  
              // close IO streams, then socket
              System.err.println("Closing connection with client");
              out.close();
              in.close();
              clientSocket.close();
          }
      }
  }
  </code></pre>
  
  <p>any tips appreciated thanks </p>