UDP Multicast Server and Client in Java

import java.io.*;
import java.net.*;
import java.util.Date;

public class MulticastServer {

	public static void main(String[] args) {
		System.out.println("Multicast Server Started!");
		DatagramSocket ds = null;
		try {
			ds = new DatagramSocket();

			while (true) {
				String date_text = new Date().toString();
				byte[] buff = new byte[256];
				buff = date_text.getBytes();
				InetAddress group = InetAddress.getByName("224.0.0.0");
				DatagramPacket dpacket;
				dpacket = new DatagramPacket(buff, buff.length, group, 8888);
				ds.send(dpacket);
				System.out.println("Time sent : " + date_text);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException ex) {

				}

			}

		} catch (SocketException se) {
			se.printStackTrace();

		} catch (IOException ioe) {
			ioe.printStackTrace();
		}

	}
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *