java.net.MulticastSocket
This class models a multicast socket for sending & receiving datagram packets
to a multicast group.
Summary
Public Constructors
Public Methods
bind,
close,
connect,
connect,
disconnect,
getBroadcast,
getChannel,
getInetAddress,
getLocalAddress,
getLocalPort,
getLocalSocketAddress,
getPort,
getReceiveBufferSize,
getRemoteSocketAddress,
getReuseAddress,
getSendBufferSize,
getSoTimeout,
getTrafficClass,
isBound,
isClosed,
isConnected,
receive,
send,
setBroadcast,
setDatagramSocketImplFactory,
setReceiveBufferSize,
setReuseAddress,
setSendBufferSize,
setSoTimeout,
setTrafficClass
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
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 |
Public Methods
Answer the network address used by the socket. This is useful on
multi-homed machines.
Returns
- java.net.InetAddress the network 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.
Answer the network interface used by the socket. This is useful on
multi-homed machines.
Returns
- java.net.NetworkInterface the network address
public
byte
getTTL()
This method is deprecated.
Replaced by getTimeToLive()
Answer the time-to-live (TTL) for multicast packets sent on this socket.
public
int
getTimeToLive()
Answer the time-to-live (TTL) for multicast packets sent on this socket.
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 |
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 |
public
void
leaveGroup(InetAddress groupAddr)
Remove the socket from the multicast group.
Parameters
groupAddr
| the multicast group to be left |
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 |
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 |
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 |
public
void
setLoopbackMode(boolean loop)
Set the IP_MULTICAST_LOOP socket option.
Parameters
loop
| the socket IP_MULTICAST_LOOP option setting |
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 |
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.
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 |