Java in a Nutshell, 5th Edition [Electronic resources]

نسخه متنی -صفحه : 1191/ 376
نمايش فراداده

MulticastSocketjava.net

Java 1.1

This subclass of DatagramSocket can send and receive multicast UDP packets. It extends DatagramSocket by adding joinGroup( ) and leaveGroup( ) methods to join and leave multicast groups. You do not have to join a group to send a packet to a multicast address, but you must join the group to receive packets sent to that address. Note that the use of a MulticastSocket is governed by a security manager.

Use setTimeToLive( ) to set a time-to-live value for any packets sent through a MulticastSocket. This constrains the number of network hops a packet can take and controls the scope of a multicast. Use setInterface( ) or setNetworkInterface( ) to specify the InetAddress or the NetworkInterface that outgoing multicast packets should use: this is useful for servers or other computers that have more than one internet address or network interface. setLoopbackMode( ) specifies whether a multicast packets sent through this socket should be send back to this socket or not. This method should really be named "setLoopbackModeDisabled( )": passing an argument of TRue requests (but does not require) that the system disable loopback packets.

Figure 12-12. java.net.MulticastSocket

public class

MulticastSocket extends DatagramSocket { // Public Constructors public

MulticastSocket ( ) throws java.io.IOException;

1.4 public

MulticastSocket (SocketAddress

bindaddr ) throws java.io.IOException; public

MulticastSocket (int

port ) throws java.io.IOException; // Public Instance Methods public InetAddress

getInterface ( ) throws SocketException; default:Inet4Address

1.4 public boolean

getLoopbackMode ( ) throws SocketException; default:false

1.4 public NetworkInterface

getNetworkInterface ( ) throws SocketException;

1.2 public int

getTimeToLive ( ) throws java.io.IOException; default:1 public void

joinGroup (InetAddress

mcastaddr ) throws java.io.IOException;

1.4 public void

joinGroup (SocketAddress

mcastaddr , NetworkInterface

netIf ) throws java.io.IOException; public void

leaveGroup (InetAddress

mcastaddr ) throws java.io.IOException;

1.4 public void

leaveGroup (SocketAddress

mcastaddr , NetworkInterface

netIf ) throws java.io.IOException; public void

setInterface (InetAddress

inf ) throws SocketException;

1.4 public void

setLoopbackMode (boolean

disable ) throws SocketException;

1.4 public void

setNetworkInterface (NetworkInterface

netIf ) throws SocketException;

1.2 public void

setTimeToLive (int

ttl ) throws java.io.IOException; // Deprecated Public Methods

# public byte

getTTL ( ) throws java.io.IOException; default:1

# public void

send (DatagramPacket

p , byte

ttl ) throws java.io.IOException;

# public void

setTTL (byte

ttl ) throws java.io.IOException; }