Skip to content

Instantly share code, notes, and snippets.

@pavinduLakshan
Created June 7, 2020 11:50
Show Gist options
  • Save pavinduLakshan/9583c7dd65978ec6d80a0384cfe4b52b to your computer and use it in GitHub Desktop.
Save pavinduLakshan/9583c7dd65978ec6d80a0384cfe4b52b to your computer and use it in GitHub Desktop.
public class MulticastServer {
public final static int MULTICAST_PORT = 50001;
public final static String MULTICAST_GROUP = "127.0.0.1";
public static void main(String[] args){
try {
DatagramSocket serverSocket = new DatagramSocket();
byte[] dataBuffer = new byte[1024];
DatagramPacket outputPacket = new DatagramPacket(
dataBuffer, dataBuffer.length,
InetAddress.getByName(MULTICAST_GROUP),
MULTICAST_PORT
);
while (true){
outputPacket.setData("Multicasting-Java Revisited");
serverSocket.send(outputPacket);
try{
thread.sleep(1000);
}
catch(InterruptedException e){
e.printStackTrace();
}
}
}
catch (InterruptedException e){
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment