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 ('224.0.0.0', '235.0.0.1', '235.255.0.1', '224.0.255.1'). 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:
MulticastSocket(int port):
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:
import javax.swing.*;
|
Output of program:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Multicast Server in Java View All Comments
Post your Comment