/*   
     Time server to return the current time and date on the server
     [coded by Arul John] <http://wolf.rules.it>
*/

import java.io.*;
import java.net.*;
import java.util.*;

class Tym {
    public static void main(String args[]) {
	try {
	    System.out.println("Time server by Arul John. It works for 10 attempts");
	    ServerSocket ss = new ServerSocket(1234);
	    int i = 0;
	    Socket s = ss.accept();
	    while (++i < 10) {
		System.out.println("Sending time and date to client #" + i);
		PrintWriter pw = new PrintWriter(s.getOutputStream());
		String date = new Date().toString();
		pw.println("time and date on server: " + date);
		pw.close();
		s = ss.accept();
	    }
	    s.close();
	    ss.close();
	} catch (Exception e) {
	    e.printStackTrace();
	}
    } // end of main
} // end of class Tym 
