加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090228222616/http://developer.android.com:80/reference/java/net/MulticastSocket.html
public class

MulticastSocket

extends DatagramSocket
java.lang.Object
   ↳ java.net.DatagramSocket
     ↳ java.net.MulticastSocket

Class Overview

This class models a multicast socket for sending & receiving datagram packets to a multicast group.

See Also

Summary

Public Constructors
MulticastSocket()
Constructs a multicast socket, bound to any available port on the localhost.
MulticastSocket(int aPort)
Returns a multicast socket, bound to the nominated port on the localhost.
MulticastSocket(SocketAddress localAddr)
Constructs a MulticastSocket bound to the host/port specified by the SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.
Public Methods
InetAddress getInterface()
Answer the network address used by the socket.
boolean getLoopbackMode()
Get the state of the IP_MULTICAST_LOOP socket option.
NetworkInterface getNetworkInterface()
Answer the network interface used by the socket.
byte getTTL()
This method is deprecated. Replaced by getTimeToLive()
int getTimeToLive()
Answer the time-to-live (TTL) for multicast packets sent on this socket.
void joinGroup(InetAddress groupAddr)
Add this socket to the multicast group.
void joinGroup(SocketAddress groupAddress, NetworkInterface netInterface)
Add this socket to the multicast group.
void leaveGroup(InetAddress groupAddr)
Remove the socket from the multicast group.
void leaveGroup(SocketAddress groupAddress, NetworkInterface netInterface)
Remove the socket from the multicast group.
void send(DatagramPacket pack, byte ttl)
This method is deprecated. use setTimeToLive(int)
void setInterface(InetAddress addr)
Set the network address used by the socket.
void setLoopbackMode(boolean loop)
Set the IP_MULTICAST_LOOP socket option.
void setNetworkInterface(NetworkInterface netInterface)
Set the network interface used by the socket.
void setTTL(byte ttl)
This method is deprecated. Replaced by setTimeToLive(int)
void setTimeToLive(int ttl)
Set the time-to-live (TTL) for multicast packets sent on this socket.
[Expand]
Inherited Methods
From class java.net.DatagramSocket
From class java.lang.Object

Public Constructors

public MulticastSocket ()

Constructs a multicast socket, bound to any available port on the localhost.

Throws
IOException if a problem occurs creating or binding the socket

public MulticastSocket (int aPort)

Returns a multicast socket, bound to the nominated port on the localhost.

Parameters
aPort the port to bind on the localhost
Throws
IOException if a problem occurs creating or binding the socket

public MulticastSocket (SocketAddress localAddr)

Constructs a MulticastSocket bound to the host/port specified by the SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.

Parameters
localAddr the local machine address and port to bind to
Throws
IllegalArgumentException if the SocketAddress is not supported
IOException if a problem occurs creating or binding the socket

Public Methods

public InetAddress getInterface ()

Answer the network address used by the socket. This is useful on multi-homed machines.

Returns
  • java.net.InetAddress the network address
Throws
SocketException The exception thrown while getting the address

public boolean getLoopbackMode ()

Get the state of the IP_MULTICAST_LOOP socket option.

Returns
  • true if the IP_MULTICAST_LOOP is enabled, false otherwise.
Throws
SocketException if the socket is closed or the option is invalid.

public NetworkInterface getNetworkInterface ()

Answer the network interface used by the socket. This is useful on multi-homed machines.

Returns
  • java.net.NetworkInterface the network address
Throws
SocketException The exception thrown while getting the address

public byte getTTL ()

This method is deprecated.Replaced by getTimeToLive()

Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns
  • java.net.InetAddress
Throws
IOException The exception description.
See Also

public int getTimeToLive ()

Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns
  • java.net.InetAddress
Throws
IOException The exception description.

public void joinGroup (InetAddress groupAddr)

Add this socket to the multicast group. A socket must joint a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters
groupAddr the multicast group to be joined
Throws
IOException may be thrown while joining a group

public void joinGroup (SocketAddress groupAddress, NetworkInterface netInterface)

Add this socket to the multicast group. A socket must join a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters
groupAddress the multicast group to be joined
netInterface the network interface on which the addresses should be dropped
Throws
IOException will be thrown if address is not a multicast address
SecurityException will be thrown if caller is not authorized to join group
IllegalArgumentException will be through if groupAddr is null

public void leaveGroup (InetAddress groupAddr)

Remove the socket from the multicast group.

Parameters
groupAddr the multicast group to be left
Throws
IOException will be thrown if address is not a multicast address
SecurityException will be thrown if caller is not authorized to join group
IllegalArgumentException will be through if groupAddr is null

public void leaveGroup (SocketAddress groupAddress, NetworkInterface netInterface)

Remove the socket from the multicast group.

Parameters
groupAddress the multicast group to be left
netInterface the network interface on which the addresses should be dropped
Throws
IOException will be thrown if address is not a multicast address
SecurityException will be thrown if caller is not authorized to join group
IllegalArgumentException will be through if groupAddr is null

public void send (DatagramPacket pack, byte ttl)

This method is deprecated.use setTimeToLive(int)

Send the packet on this socket. The packet must satisfy the security policy before it may be sent.

Parameters
pack the DatagramPacket to send
ttl the TTL setting for this transmission, overriding the socket default
Throws
IOException If a send error occurs.

public void setInterface (InetAddress addr)

Set the network address used by the socket. This is useful on multi-homed machines.

Parameters
addr java.net.InetAddress the interface network address
Throws
SocketException the exception may be thrown while setting the address

public void setLoopbackMode (boolean loop)

Set the IP_MULTICAST_LOOP socket option.

Parameters
loop the socket IP_MULTICAST_LOOP option setting
Throws
SocketException if the socket is closed or the option is invalid.

public void setNetworkInterface (NetworkInterface netInterface)

Set the network interface used by the socket. This is useful on multi-homed machines.

Parameters
netInterface NetworkInterface the interface to be used
Throws
SocketException the exception may be thrown while setting the address

public void setTTL (byte ttl)

This method is deprecated.Replaced by setTimeToLive(int)

Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters
ttl the time-to-live, 0
Throws
IOException The exception thrown while setting the TTL

public void setTimeToLive (int ttl)

Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters
ttl the time-to-live, 0<=ttl<= 255
Throws
IOException The exception thrown while setting the TTL