import java.io.*;
import java.net.*;
import java.util.*;

public class MultiDateServer {
    private DatagramSocket socket;
    private boolean broadcast = true;
    private String group = "230.0.0.1";
    private int port = 4446;
    private int delay = 2000;

    public void start() throws Exception{
        DatagramPacket packet;
        InetAddress address = InetAddress.getByName(group);
        socket = new DatagramSocket(port);
        while (broadcast) {
            try {
                byte[] buf = new byte[256];
                String dString = new Date().toString();
                buf = dString.getBytes();
                packet = new DatagramPacket(buf, buf.length, address, port);
                socket.send(packet);
            } catch (IOException e) {
                broadcast = false;
            }
            try{
                Thread.sleep(delay);
            } catch (InterruptedException e){
                System.exit(0);
            }
        }
        socket.close();
    }
    public static void main(String[] args) throws Exception{
        MultiDateServer server = new MultiDateServer();
        server.start();
    }
}
