MuiticastSocket in Java

0
26
Spread the love
  • 23
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    160
    Shares

MuiticastSocket in Java

This subclass of DatagramSocket is used to send and receive multicast UDP packets. It extends DatagramSocket by adding joinGroup() and leaveGroup() methods to join and leave multicast groups. The IP address specified to these methods should be a valid multicast address in the range of 224. 0. 0. 1 to 239. 255. 255. 255. We do not have to join a group to send a packet to a multicast address, but we must join the group to receive packets sent to that address.

MulticastSocket defines a variant send() method that allows us to specify a time to – live (TTL) value for the packet we send. This value specifies the number of network ” hops ” the packet may travel before it expires. we can also set a default TTL for all packets sent through a MulticastSocket with setTTLO.

Untrusted applets are not allowed to use multicast sockets.

The class structure of MuiticastSocket is given as:

public class java.net.MulticastSocket extends java.net.DatagramSocket{
// Public Constructors  
public MulticastSocket() throws IOException;
public MulticastSocket(int port) throws IOException;
// Public Instance Methods 
public InetAddress getInterface() throws SocketException;
public byte getTTL() throws IOException;
public void joinGroup(InetAddress mcastaddr) throws IOException;
public void leaveGroup(InetAddress mcastaddr) throws IOException;
public synchronized void send(DatagramPacket p, byte ttl) throws IOException; 
public void setInterface (InetAddress inetAddr) throws SocketException;
public void setTTL(byte ttl) throws IOException;
}
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 23
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    160
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here