📄 multicastsocket.html
字号:
<PRE>public <B>MulticastSocket</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Create a multicast socket. <p>If there is a security manager, its <code>checkListen</code> method is first called with 0 as its argument to ensure the operation is allowed. This could result in a SecurityException.<DD><DL><DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O exception occurs while creating the MulticastSocket<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkListen</code> method doesn't allow the operation.<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL></DD></DL><HR><A NAME="MulticastSocket(int)"><!-- --></A><H3>MulticastSocket</H3><PRE>public <B>MulticastSocket</B>(int port) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Create a multicast socket and bind it to a specific port. <p>If there is a security manager, its <code>checkListen</code> method is first called with the <code>port</code> argument as its argument to ensure the operation is allowed. This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>port</CODE> - port to use<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O exception occurs while creating the MulticastSocket<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkListen</code> method doesn't allow the operation.<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkListen(int)"><CODE>SecurityManager.checkListen(int)</CODE></A></DL></DD></DL><!-- ============ METHOD DETAIL ========== --><A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Method Detail</B></FONT></TD></TR></TABLE><A NAME="setTTL(byte)"><!-- --></A><H3>setTTL</H3><PRE>public void <B>setTTL</B>(byte ttl) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD><B>Deprecated.</B> <I>use the setTimeToLive method instead, which uses <b>int</b> instead of <b>byte</b> as the type for ttl.</I><P><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>.<DD><DL><DT><B>Parameters:</B><DD><CODE>ttl</CODE> - the time-to-live<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O exception occurs while setting the default time-to-live value<DT><B>See Also: </B><DD><A HREF="../../java/net/MulticastSocket.html#getTTL()"><CODE>getTTL()</CODE></A></DL></DD></DL><HR><A NAME="setTimeToLive(int)"><!-- --></A><H3>setTimeToLive</H3><PRE>public void <B>setTimeToLive</B>(int ttl) throws <A HREF="../../java/io/IOException.html">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 <B>must</B> be in the range <code> 0 <= ttl <= 255</code> or an IllegalArgumentException will be thrown.<DD><DL><DT><B>Parameters:</B><DD><CODE>ttl</CODE> - the time-to-live<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O exception occurs while setting the default time-to-live value<DT><B>See Also: </B><DD><A HREF="../../java/net/MulticastSocket.html#getTimeToLive()"><CODE>getTimeToLive()</CODE></A></DL></DD></DL><HR><A NAME="getTTL()"><!-- --></A><H3>getTTL</H3><PRE>public byte <B>getTTL</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD><B>Deprecated.</B> <I>use the getTimeToLive method instead, which returns an <b>int</b> instead of a <b>byte</b>.</I><P><DD>Get the default time-to-live for multicast packets sent out on the socket.<DD><DL><DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O exception occurs while getting the default time-to-live value<DT><B>See Also: </B><DD><A HREF="../../java/net/MulticastSocket.html#setTTL(byte)"><CODE>setTTL(byte)</CODE></A></DL></DD></DL><HR><A NAME="getTimeToLive()"><!-- --></A><H3>getTimeToLive</H3><PRE>public int <B>getTimeToLive</B>() throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Get the default time-to-live for multicast packets sent out on the socket.<DD><DL><DT><B>Returns:</B><DD>the default time-to-live value<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O exception occurs while getting the default time-to-live value<DT><B>See Also: </B><DD><A HREF="../../java/net/MulticastSocket.html#setTimeToLive(int)"><CODE>setTimeToLive(int)</CODE></A></DL></DD></DL><HR><A NAME="joinGroup(java.net.InetAddress)"><!-- --></A><H3>joinGroup</H3><PRE>public void <B>joinGroup</B>(<A HREF="../../java/net/InetAddress.html">InetAddress</A> mcastaddr) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Joins a multicast group.Its behavior may be affected by <code>setInterface</code>. <p>If there is a security manager, this method first calls its <code>checkMulticast</code> method with the <code>mcastaddr</code> argument as its argument.<DD><DL><DT><B>Parameters:</B><DD><CODE>mcastaddr</CODE> - is the multicast address to join<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if there is an error joining or when the address is not a multicast address.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkMulticast</code> method doesn't allow the join.<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkMulticast(java.net.InetAddress)"><CODE>SecurityManager.checkMulticast(InetAddress)</CODE></A></DL></DD></DL><HR><A NAME="leaveGroup(java.net.InetAddress)"><!-- --></A><H3>leaveGroup</H3><PRE>public void <B>leaveGroup</B>(<A HREF="../../java/net/InetAddress.html">InetAddress</A> mcastaddr) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Leave a multicast group. Its behavior may be affected by <code>setInterface</code>. <p>If there is a security manager, this method first calls its <code>checkMulticast</code> method with the <code>mcastaddr</code> argument as its argument.<DD><DL><DT><B>Parameters:</B><DD><CODE>mcastaddr</CODE> - is the multicast address to leave<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if there is an error leaving or when the address is not a multicast address.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkMulticast</code> method doesn't allow the operation.<DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkMulticast(java.net.InetAddress)"><CODE>SecurityManager.checkMulticast(InetAddress)</CODE></A></DL></DD></DL><HR><A NAME="setInterface(java.net.InetAddress)"><!-- --></A><H3>setInterface</H3><PRE>public void <B>setInterface</B>(<A HREF="../../java/net/InetAddress.html">InetAddress</A> inf) throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Set the multicast network interface used by methods whose behavior would be affected by the value of the network interface. Useful for multihomed hosts.<DD><DL><DT><B>Parameters:</B><DD><CODE>inf</CODE> - the InetAddress<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if there is an error in the underlying protocol, such as a TCP error.<DT><B>See Also: </B><DD><A HREF="../../java/net/MulticastSocket.html#getInterface()"><CODE>getInterface()</CODE></A></DL></DD></DL><HR><A NAME="getInterface()"><!-- --></A><H3>getInterface</H3><PRE>public <A HREF="../../java/net/InetAddress.html">InetAddress</A> <B>getInterface</B>() throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Retrieve the address of the network interface used for multicast packets.<DD><DL><DT><B>Returns:</B><DD>An <code>InetAddress</code> representing the address of the network interface used for multicast packets.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if there is an error in the underlying protocol, such as a TCP error.<DT><B>See Also: </B><DD><A HREF="../../java/net/MulticastSocket.html#setInterface(java.net.InetAddress)"><CODE>setInterface(java.net.InetAddress)</CODE></A></DL></DD></DL><HR><A NAME="send(java.net.DatagramPacket, byte)"><!-- --></A><H3>send</H3><PRE>public void <B>send</B>(<A HREF="../../java/net/DatagramPacket.html">DatagramPacket</A> p, byte ttl) throws <A HREF="../../java/io/IOException.html">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. Its behavior may be affected by <code>setInterface</code>. <p>If there is a security manager, this method first performs some security checks. First, if <code>p.getAddress().isMulticastAddress()</code> is true, this method calls the security manager's <code>checkMulticast</code> method with <code>p.getAddress()</code> and <code>ttl</code> as its arguments. If the evaluation of that expression is false, this method instead calls the security manager's <code>checkConnect</code> method with arguments <code>p.getAddress().getHostAddress()</code> and <code>p.getPort()</code>. Each call to a security manager method could result in a SecurityException if the operation is not allowed.<DD><DL><DT><B>Parameters:</B><DD><CODE>p</CODE> - 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><CODE>ttl</CODE> - optional time to live for multicast packet. default ttl is 1.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - is raised if an error occurs i.e error while setting ttl.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkMulticast</code> or <code>checkConnect</code> method doesn't allow the send.<DT><B>See Also: </B><DD><A HREF="../../java/net/DatagramSocket.html#send(java.net.DatagramPacket)"><CODE>DatagramSocket.send(java.net.DatagramPacket)</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#receive(java.net.DatagramPacket)"><CODE>DatagramSocket.receive(java.net.DatagramPacket)</CODE></A>, <A HREF="../../java/lang/SecurityManager.html#checkMulticast(java.net.InetAddress, byte)"><CODE>SecurityManager.checkMulticast(java.net.InetAddress, byte)</CODE></A>, <A HREF="../../java/lang/SecurityManager.html#checkConnect(java.lang.String, int)"><CODE>SecurityManager.checkConnect(java.lang.String, int)</CODE></A></DL></DD></DL><!-- ========= END OF CLASS DATA ========= --><HR><!-- ========== START OF NAVBAR ========== --><A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0"><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3"> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/MulticastSocket.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup> 2 Platform<br>Std. Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../java/net/JarURLConnection.html"><B>PREV CLASS</B></A> <A HREF="../../java/net/NetPermission.html"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../index.html" TARGET="_top"><B>FRAMES</B></A> <A HREF="MulticastSocket.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: INNER | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><!-- =========== END OF NAVBAR =========== --><HR><font size="-1"><a href="http://java.sun.com/cgi-bin/bugreport.cgi">Submit a bug or feature</a><br>For further API reference and developer documentation, see <a href="http://java.sun.com/products/jdk/1.3/devdocs-vs-specs.html">Java 2 SDK SE Developer Documentation</a>. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. <p>Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.<br>Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road<br>Palo Alto, California, 94303, U.S.A. All Rights Reserved.</font></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -