/** 
 * This program is an example from the book "Internet 
 * programming with Java" by Svetlin Nakov. It is freeware. 
 * For more information: http://www.nakov.com/books/inetjava/ 
 */ 
import java.util.Date; 
import java.io.OutputStreamWriter; 
import java.io.IOException; 
import java.net.Socket; 
import java.net.ServerSocket; 
 
public class DateServer { 
    public static void main(String[] args) throws IOException { 
        ServerSocket serverSocket = new ServerSocket(2002); 
        while (true) { 
        Socket socket = serverSocket.accept(); 
            OutputStreamWriter out = 
                new OutputStreamWriter( 
                    socket.getOutputStream()); 
            out.write(new Date()+ "\n"); 
            out.close(); 
            socket.close(); 
        } 
    } 
}
Back to Internet Programming with Java books's web site