创建时间服务器以提供时间值
import java.io.BufferedOutputStream; import java.io.IOException; import java.io.PrintWriter;//时代Java 提 供 import java.net.ServerSocket; import java.net.Socket; import java.util.Date; public class Main extends Thread { private ServerSocket sock; public Main() { super(); try { /*来自 时 代 J a v a - nowjava.com*/ sock = new ServerSocket(4415); System.out.println("TimeServer running ..."); } catch (IOException e) { System.out.println("Error: couldn't create socket."); System.exit(1); } } public void run() { Socket client = null; while (true) { if (sock == null) return; try { client = sock.accept(); BufferedOutputStream bos = new BufferedOutputStream( client.getOutputStream()); PrintWriter os = new PrintWriter(bos, false); Date now = new Date(); os.println(now); os.flush(); os.close(); client.close(); } catch (IOException e) { System.out.prin