import java.net.*;
import java.io.*;
import java.util.Random;
import java.util.Date;

public class DateServer {
    public static void main(String[] args) throws IOException {
        new Thread(new SendDateTask()).start();
    }
}

class SendDateTask implements Runnable{

    private static final int PORT_NUMBER = 8899;
    protected DatagramSocket socket = null;
    protected BufferedReader in = null;
    private Random random = new Random();

    public SendDateTask() throws IOException {
        socket = new DatagramSocket(PORT_NUMBER);
    }

    public void run() {
        try {
            while (true) {
                byte[] buf = new byte[256];   // create buffer for packet
                DatagramPacket packet = new DatagramPacket(buf, 256);
                socket.receive(packet);       // wait for client’s packet
                String date = new Date().toString();
                buf = date.getBytes();       // copy number to packet

                // create a new datagram with the client’s IP address and port
                InetAddress address = packet.getAddress();
                int port = packet.getPort();
                packet = new DatagramPacket(buf, buf.length, address, port);
                socket.send(packet);         // send packet to client
            }
        } catch (IOException e) {}
    }
}