Created
June 7, 2020 11:50
-
-
Save pavinduLakshan/9583c7dd65978ec6d80a0384cfe4b52b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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