<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--NewPage-->
<html>
<head>
<!-- Generated by javadoc on Wed Jul 28 01:21:15 GMT 1999 -->
<title>
  Class java.net.MulticastSocket
</title>
</head>
<body>
<a name="_top_"></a>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.net.html">This Package</a>  <a href="java.net.InetAddress.html#_top_">Previous</a>  <a href="java.net.ServerSocket.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
<hr>
<h1>
  Class java.net.MulticastSocket
</h1>
<pre>
<a href="java.lang.Object.html#_top_">java.lang.Object</a>
   |
   +----<a href="java.net.DatagramSocket.html#_top_">java.net.DatagramSocket</a>
           |
           +----java.net.MulticastSocket
</pre>
<hr>
<dl>
  <dt> public class <b>MulticastSocket</b>
  <dt> extends <a href="java.net.DatagramSocket.html#_top_">DatagramSocket</a>
</dl>
The multicast datagram socket class is useful for sending
 and receiving IP multicast packets.  A MulticastSocket is
 a (UDP) DatagramSocket, with additional capabilities for
 joining "groups" of other multicast hosts on the internet.
 <P>
 A multicast group is specified by a class D IP address, those
 in the range <CODE>224.0.0.1</CODE> to <CODE>239.255.255.255</CODE>, 
 inclusive, and by a standard UDP port number.  One would join a 
 multicast group by first creating a MulticastSocket with the desired
 port, then invoking the <CODE>joinGroup(InetAddress groupAddr)</CODE>
 method:
 <PRE>
 // join a Multicast group and send the group salutations
 ...
 byte[] msg = {'H', 'e', 'l', 'l', 'o'};
 InetAddress group = InetAddress.getByName("228.5.6.7");
 MulticastSocket s = new MulticastSocket(6789);
 s.joinGroup(group);
 DatagramPacket hi = new DatagramPacket(msg, msg.length,
                             group, 6789);
 s.send(hi);
 // get their responses! 
 byte[] buf = new byte[1000];
 DatagramPacket recv = new DatagramPacket(buf, buf.length);
 s.receive(recv);
 ...
 // OK, I'm done talking - leave the group...
 s.leaveGroup(group);
 </PRE>
 When one sends a message to a multicast group, <B>all</B> subscribing
 recipients to that host and port receive the message (within the
 time-to-live range of the packet, see below).  The socket needn't
 be a member of the multicast group to send messages to it.
 <P>
 When a socket subscribes to a multicast group/port, it receives
 datagrams sent by other hosts to the group/port, as do all other
 members of the group and port.  A socket relinquishes membership
 in a group by the leaveGroup(InetAddress addr) method.  <B> 
 Multiple MulticastSocket's</B> may subscribe to a multicast group
 and port concurrently, and they will all receive group datagrams.
 <P>
 Currently applets are not allowed ot use multicast sockets.
<p>
<hr>
<a name="index"></a>
<h2>
  <img src="images/constructor-index.gif" width=275 height=38 alt="Constructor Index">
</h2>
<dl>
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#MulticastSocket()"><b>MulticastSocket</b></a>()
  <dd>  Create a multicast socket.
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#MulticastSocket(int)"><b>MulticastSocket</b></a>(int)
  <dd>  Create a multicast socket and bind it to a specific port.
</dl>
<h2>
  <img src="images/method-index.gif" width=207 height=38 alt="Method Index">
</h2>
<dl>
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getInterface()"><b>getInterface</b></a>()
  <dd>  Retrieve the address of the network interface used for
 multicast packets.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getTTL()"><b>getTTL</b></a>()
  <dd>  Get the default time-to-live for multicast packets sent out
 on the socket.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#joinGroup(java.net.InetAddress)"><b>joinGroup</b></a>(InetAddress)
  <dd>  Joins a multicast group.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#leaveGroup(java.net.InetAddress)"><b>leaveGroup</b></a>(InetAddress)
  <dd>  Leave a multicast group.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#send(java.net.DatagramPacket, byte)"><b>send</b></a>(DatagramPacket, byte)
  <dd>  Sends a datagram packet to the destination, with a TTL (time-
 to-live) other than the default for the socket.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#setInterface(java.net.InetAddress)"><b>setInterface</b></a>(InetAddress)
  <dd>  Set the outgoing network interface for multicast packets on this
 socket, to other than the system default.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#setTTL(byte)"><b>setTTL</b></a>(byte)
  <dd>  Set the default time-to-live for multicast packets sent out
 on this socket.
</dl>
<a name="constructors"></a>
<h2>
  <img src="images/constructors.gif" width=231 height=38 alt="Constructors">
</h2>
<a name="MulticastSocket"></a>
<a name="MulticastSocket()"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>MulticastSocket</b>
<pre>
 public MulticastSocket() throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Create a multicast socket.
<p>
</dl>
<a name="MulticastSocket(int)"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>MulticastSocket</b>
<pre>
 public MulticastSocket(int port) throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Create a multicast socket and bind it to a specific port.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> local - port to use
  </dl></dd>
</dl>
<a name="methods"></a>
<h2>
  <img src="images/methods.gif" width=151 height=38 alt="Methods">
</h2>
<a name="setTTL(byte)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="setTTL"><b>setTTL</b></a>
<pre>
 public void setTTL(byte ttl) throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Set the default time-to-live for multicast packets sent out
 on this socket.  The TTL sets the IP time-to-live for
 <code>DatagramPackets</code> sent to a MulticastGroup, which
 specifies how many "hops" that the packet will be forwarded
 on the network before it expires.
 <P>
 The ttl is an <b>unsigned</b> 8-bit quantity, and so <B>must</B> be
 in the range <code> 0 < ttl <= 0xFF </code>.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> ttl - the time-to-live
  </dl></dd>
</dl>
<a name="getTTL()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getTTL"><b>getTTL</b></a>
<pre>
 public byte getTTL() throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Get the default time-to-live for multicast packets sent out
 on the socket.
<p>
</dl>
<a name="joinGroup(java.net.InetAddress)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="joinGroup"><b>joinGroup</b></a>
<pre>
 public void joinGroup(<a href="java.net.InetAddress.html#_top_">InetAddress</a> mcastaddr) throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Joins a multicast group.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> mcastaddr - is the multicast address to join
    <dt> <b>Throws:</b> <a href="java.io.IOException.html#_top_">IOException</a>
    <dd> is raised if there is an error joining
 or when address is not a multicast address.
  </dl></dd>
</dl>
<a name="leaveGroup(java.net.InetAddress)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="leaveGroup"><b>leaveGroup</b></a>
<pre>
 public void leaveGroup(<a href="java.net.InetAddress.html#_top_">InetAddress</a> mcastaddr) throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Leave a multicast group.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> mcastaddr - is the multicast address to leave
    <dt> <b>Throws:</b> <a href="java.io.IOException.html#_top_">IOException</a>
    <dd> is raised if there is an error leaving
 or when address is not a multicast address.
  </dl></dd>
</dl>
<a name="setInterface(java.net.InetAddress)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="setInterface"><b>setInterface</b></a>
<pre>
 public void setInterface(<a href="java.net.InetAddress.html#_top_">InetAddress</a> inf) throws <a href="java.net.SocketException.html#_top_">SocketException</a>
</pre>
<dl>
  <dd> Set the outgoing network interface for multicast packets on this
 socket, to other than the system default.  Useful for multihomed
 hosts.
<p>
</dl>
<a name="getInterface()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getInterface"><b>getInterface</b></a>
<pre>
 public <a href="java.net.InetAddress.html#_top_">InetAddress</a> getInterface() throws <a href="java.net.SocketException.html#_top_">SocketException</a>
</pre>
<dl>
  <dd> Retrieve the address of the network interface used for
 multicast packets.
<p>
</dl>
<a name="send(java.net.DatagramPacket, byte)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="send"><b>send</b></a>
<pre>
 public synchronized void send(<a href="java.net.DatagramPacket.html#_top_">DatagramPacket</a> p,
                               byte ttl) throws <a href="java.io.IOException.html#_top_">IOException</a>
</pre>
<dl>
  <dd> Sends a datagram packet to the destination, with a TTL (time-
 to-live) other than the default for the socket.  This method
 need only be used in instances where a particular TTL is desired;
 otherwise it is preferable to set a TTL once on the socket, and
 use that default TTL for all packets.  This method does <B>not
 </B> alter the default TTL for the socket.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> p - is the packet to be sent. The packet should contain
 the destination multicast ip address and the data to be sent.
 One does not need to be the member of the group to send
 packets to a destination multicast address.
    <dd> ttl - optional time to live for multicast packet.
 default ttl is 1.
    <dt> <b>Throws:</b> <a href="java.io.IOException.html#_top_">IOException</a>
    <dd> is raised if an error occurs i.e
 error while setting ttl.
    <dt> <b>See Also:</b>
    <dd> <a href="java.net.DatagramSocket.html#send">send</a>, <a href="java.net.DatagramSocket.html#receive">receive</a>
  </dl></dd>
</dl>
<hr>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.net.html">This Package</a>  <a href="java.net.InetAddress.html#_top_">Previous</a>  <a href="java.net.ServerSocket.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
</body>
</html>
