import java.io.*; import java.net.*; import java.util.Date; public class DateServer extends Thread { public final static int PORT = 13; protected ServerSocket listen_socket; // Create a ServerSocket to listen to; public DateServer() { try { listen_socket = new ServerSocket(PORT); } catch (IOException e) { System.err.println("Exception creating server" + " socket: " + e); System.exit(1); } // fire up the Thread's run() method this.start(); } public void run() { PrintStream out; try { while(true) { Socket client_socket = listen_socket.accept(); try { out = new PrintStream(client_socket.getOutputStream()); } catch (IOException e) { try { client_socket.close(); } catch (IOException e2) {} ; System.err.println("Exception while getting" + " socket streams: " + e); return; } out.println(new Date()); client_socket.close(); } //End of while(true) loop } catch (IOException e) { // Any IOException in big loop System.err.println("Exception while listening" + " for connections: " + e); System.exit(2); } } // Start the server up, listening on an optionally specified port public static void main(String[] args) { new DateServer(); } }