This section introduces how to receive and send the IP packet by the multicast server and provides the functionality of multicast server through program. A brief description is given bellow.
Description of program:
Here, a graphical layout appears on the screen when program runs that has two command buttons 'Start' and 'Stop'. First time 'Start' button is enable and another is disable. When you click 'Start' button, the multicast server functions but button is disable, and the message "Server is started" is displayed in text area. If you want to stop the server then click on the 'Stop' button then multicast server resume its function with a message that "Server is stopped". The multicast server receives requests or messages from multicast client, which has the port number '5000' and IP(Internate Protocol) number ('126.96.36.199', '188.8.131.52', '184.108.40.206', '220.127.116.11'). The server also sends same message to all multicast clients that are interested for this group otherwise don't perform these works.
Description of code:
This is the constructor of MulticastSocket class. This class imports from import java.net.* package and extends the DatagramSocket that can be used for sending or receiving the multicast IP packets. It is same as DatagramSocket (UDP) and provides an extra facility to joining 'groups' of multicast hosts on the Internet. The above constructor constructs multicast socket. It takes integer type port number to bound it.
DatagramPacket(byte buf, int length, InetAddress
address, int port):
DatagramPacket is a constructor of DatagramPacket class. This class extends the Object and imports form import java.net.* package that can be used for delivering the connectionless packet so packet delivering is not guarantee at the destination host. This constructor creates a datagram packet and delivers or transfers packet length to specified port number at the specified host.
Here is the code of program:
Output of program:
Liked it! Share this Tutorial