How can I make the client stays on until the server makes a connection..Java? : //Client
  
  `enter code here`  public class MyClient {
      public static void main(String[] args) throws  IOException, SocketException,     ConnectException {
        ServerSocket serverSocket = null;
        Socket clientSocket = null;
        BufferedReader in = null;
        
        System.out.println("Welcome to the Daytime client.");
        try{
        clientSocket = new Socket("localhost", 4321);
             while(true){
    		   in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
    		   String s = in.readLine();
    		   System.out.println("Here is the timestamp received from the server: "+s); 
    		   System.out.println("The program terminated with no error and no exception");
    		 in.close();     
    	     clientSocket.close(); 
    	     clientSocket.close();
            }
    		}catch (ConnectException e){
    		 System.exit(0); 
    	    }catch (SocketException f){
    		 System.exit(0); 
    		}catch (IOException e) {
    		System.out.println("Error: " + e); 
    		System.exit(0); 
    		} 	  
       }    
    }
    
//SERVER
    
    import java.io.*;
    import java.net.*;
    import java.util.*;
    
    public class MyServer {
      public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = null;
        Socket clientSocket = null;
        PrintWriter out = null;
        
        System.out.println("Daytime server ready."); 
        
        try {
          serverSocket = new ServerSocket(4321);
           while(true){
              clientSocket = serverSocket.accept(); 
              System.out.println("Request received.");
               out = new PrintWriter(clientSocket.getOutputStream(), true);
               Date timestamp = new Date ();
              out.println(timestamp.toString());
            }
          } catch (IOException e) {
            System.out.println("Error: " + e);
            System.exit(0);
          }
          out.close();
          clientSocket.close();
          serverSocket.close();
    	  System.out.println("3"); 
    
        }
      }

