⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketoptions.html

📁 API資料大全
💻 HTML
📖 第 1 页 / 共 2 页
字号:
IP_MULTICAST_IF</H3><PRE>public static final int <B>IP_MULTICAST_IF</B></PRE><DL><DD>Set which outgoing interface on which to send multicast packets. Useful on hosts with multiple network interfaces, where applications want to use other than the system default.  Takes/returns an InetAddress. <P> Valid for Multicast: DatagramSocketImpl <P><DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/net/MulticastSocket.html#setInterface(java.net.InetAddress)"><CODE>MulticastSocket.setInterface(java.net.InetAddress)</CODE></A>, <CODE>MulitcastSocket#getInterface</CODE></DL></DD></DL><HR><A NAME="SO_LINGER"><!-- --></A><H3>SO_LINGER</H3><PRE>public static final int <B>SO_LINGER</B></PRE><DL><DD>Specify a linger-on-close timeout.  This option disables/enables immediate return from a <B>close()</B> of a TCP Socket.  Enabling this option with a non-zero Integer <I>timeout</I> means that a <B>close()</B> will block pending the transmission and acknowledgement of all data written to the peer, at which point the socket is closed <I>gracefully</I>.  Upon reaching the linger timeout, the socket is closed <I>forcefully</I>, with a TCP RST. Enabling the option with a timeout of zero does a forceful close immediately. If the specified timeout value exceeds 65,535 it will be reduced to 65,535. <P> Valid only for TCP: SocketImpl<DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setSoLinger(boolean, int)"><CODE>Socket.setSoLinger(boolean, int)</CODE></A>, <A HREF="../../java/net/Socket.html#getSoLinger()"><CODE>Socket.getSoLinger()</CODE></A></DL></DD></DL><HR><A NAME="SO_TIMEOUT"><!-- --></A><H3>SO_TIMEOUT</H3><PRE>public static final int <B>SO_TIMEOUT</B></PRE><DL><DD>Set a timeout on blocking Socket operations: <PRE> ServerSocket.accept(); SocketInputStream.read(); DatagramSocket.receive(); </PRE> <P> The option must be set prior to entering a blocking operation to take effect.  If the timeout expires and the operation would continue to block, <B>java.io.InterruptedIOException</B> is raised.  The Socket is not closed in this case. <P> Valid for all sockets: SocketImpl, DatagramSocketImpl<DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setSoTimeout(int)"><CODE>Socket.setSoTimeout(int)</CODE></A>, <A HREF="../../java/net/ServerSocket.html#setSoTimeout(int)"><CODE>ServerSocket.setSoTimeout(int)</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#setSoTimeout(int)"><CODE>DatagramSocket.setSoTimeout(int)</CODE></A></DL></DD></DL><HR><A NAME="SO_SNDBUF"><!-- --></A><H3>SO_SNDBUF</H3><PRE>public static final int <B>SO_SNDBUF</B></PRE><DL><DD>Set a hint the size of the underlying buffers used by the platform for outgoing network I/O. When used in set, this is a suggestion to the kernel from the application about the size of buffers to use for the data to be sent over the socket. When used in get, this must return the size of the buffer actually used by the platform when sending out data on this socket. Valid for all sockets: SocketImpl, DatagramSocketImpl<DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setSendBufferSize(int)"><CODE>Socket.setSendBufferSize(int)</CODE></A>, <A HREF="../../java/net/Socket.html#getSendBufferSize()"><CODE>Socket.getSendBufferSize()</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#setSendBufferSize(int)"><CODE>DatagramSocket.setSendBufferSize(int)</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#getSendBufferSize()"><CODE>DatagramSocket.getSendBufferSize()</CODE></A></DL></DD></DL><HR><A NAME="SO_RCVBUF"><!-- --></A><H3>SO_RCVBUF</H3><PRE>public static final int <B>SO_RCVBUF</B></PRE><DL><DD>Set a hint the size of the underlying buffers used by the platform for incoming network I/O. When used in set, this is a suggestion to the kernel from the application about the size of buffers to use for the data to be received over the socket. When used in get, this must return the size of the buffer actually used by the platform when receiving in data on this socket. Valid for all sockets: SocketImpl, DatagramSocketImpl<DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setReceiveBufferSize(int)"><CODE>Socket.setReceiveBufferSize(int)</CODE></A>, <A HREF="../../java/net/Socket.html#getReceiveBufferSize()"><CODE>Socket.getReceiveBufferSize()</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#setReceiveBufferSize(int)"><CODE>DatagramSocket.setReceiveBufferSize(int)</CODE></A>, <A HREF="../../java/net/DatagramSocket.html#getReceiveBufferSize()"><CODE>DatagramSocket.getReceiveBufferSize()</CODE></A></DL></DD></DL><HR><A NAME="SO_KEEPALIVE"><!-- --></A><H3>SO_KEEPALIVE</H3><PRE>public static final int <B>SO_KEEPALIVE</B></PRE><DL><DD>When the keepalive option is set for a TCP socket and no data has been exchanged across the socket in either direction for  2 hours (NOTE: the actual value is implementation dependent), TCP automatically sends a keepalive probe to the peer. This probe is a  TCP segment to which the peer must respond.  One of three responses is expected: 1. The peer responds with the expected ACK. The application is not     notified (since everything is OK). TCP will send another probe     following another 2 hours of inactivity. 2. The peer responds with an RST, which tells the local TCP that    the peer host has crashed and rebooted. The socket is closed. 3. There is no response from the peer. The socket is closed.  The purpose of this option is to detect if the peer host crashes.  Valid only for TCP socket: SocketImpl<DD><DL><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setKeepAlive(boolean)"><CODE>Socket.setKeepAlive(boolean)</CODE></A>, <A HREF="../../java/net/Socket.html#getKeepAlive()"><CODE>Socket.getKeepAlive()</CODE></A></DL></DD></DL><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ 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="setOption(int, java.lang.Object)"><!-- --></A><H3>setOption</H3><PRE>public void <B>setOption</B>(int&nbsp;optID,                      <A HREF="../../java/lang/Object.html">Object</A>&nbsp;value)               throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Enable/disable the option specified by <I>optID</I>.  If the option is to be enabled, and it takes an option-specific "value",  this is passed in <I>value</I>.  The actual type of value is option-specific, and it is an error to pass something that isn't of the expected type: <BR><PRE> SocketImpl s; ... s.setOption(SO_LINGER, new Integer(10));    // OK - set SO_LINGER w/ timeout of 10 sec. s.setOption(SO_LINGER, new Double(10));    // ERROR - expects java.lang.Integer</PRE> If the requested option is binary, it can be set using this method by a java.lang.Boolean: <BR><PRE> s.setOption(TCP_NODELAY, new Boolean(true));    // OK - enables TCP_NODELAY, a binary option </PRE> <BR> Any option can be disabled using this method with a Boolean(false): <BR><PRE> s.setOption(TCP_NODELAY, new Boolean(false));    // OK - disables TCP_NODELAY s.setOption(SO_LINGER, new Boolean(false));    // OK - disables SO_LINGER </PRE> <BR> For an option that has a notion of on and off, and requires  a non-boolean parameter, setting its value to anything other than <I>Boolean(false)</I> implicitly enables it. <BR> Throws SocketException if the option is unrecognized, the socket is closed, or some low-level error occurred <BR><DD><DL><DT><B>Parameters:</B><DD><CODE>optID</CODE> - identifies the option<DD><CODE>value</CODE> - the parameter of the socket option<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if the option is unrecognized, the socket is closed, or some low-level error occurred<DT><B>See Also: </B><DD><A HREF="../../java/net/SocketOptions.html#getOption(int)"><CODE>getOption(int)</CODE></A></DL></DD></DL><HR><A NAME="getOption(int)"><!-- --></A><H3>getOption</H3><PRE>public <A HREF="../../java/lang/Object.html">Object</A> <B>getOption</B>(int&nbsp;optID)                 throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Fetch the value of an option. Binary options will return java.lang.Boolean(true) if enabled, java.lang.Boolean(false) if disabled, e.g.: <BR><PRE> SocketImpl s; ... Boolean noDelay = (Boolean)(s.getOption(TCP_NODELAY)); if (noDelay.booleanValue()) {     // true if TCP_NODELAY is enabled... ... } </PRE> <P> For options that take a particular type as a parameter, getOption(int) will return the paramter's value, else it will return java.lang.Boolean(false): <PRE> Object o = s.getOption(SO_LINGER); if (o instanceof Integer) {     System.out.print("Linger time is " + ((Integer)o).intValue()); } else {   // the true type of o is java.lang.Boolean(false); } </PRE><DD><DL><DT><B>Parameters:</B><DD><CODE>optID</CODE> - an <code>int</code> identifying the option to fetch<DT><B>Returns:</B><DD>the value of the option<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if the socket is closed<DD><CODE><A HREF="../../java/net/SocketException.html">SocketException</A></CODE> - if <I>optID</I> is unknown along the         protocol stack (including the SocketImpl)<DT><B>See Also: </B><DD><A HREF="../../java/net/SocketOptions.html#setOption(int, java.lang.Object)"><CODE>setOption(int, java.lang.Object)</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>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> &nbsp;<FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="class-use/SocketOptions.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../index-files/index-1.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A>&nbsp;</TD>  <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1">    <A HREF="../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A>&nbsp;</TD>  </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM><b>Java<sup><font size=-2>TM</font></sup>&nbsp;2&nbsp;Platform<br>Std.&nbsp;Ed. v1.3</b></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">&nbsp;<A HREF="../../java/net/SocketImplFactory.html"><B>PREV CLASS</B></A>&nbsp;&nbsp;<A HREF="../../java/net/URLStreamHandlerFactory.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>  &nbsp;&nbsp;<A HREF="SocketOptions.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">  SUMMARY: &nbsp;INNER&nbsp;|&nbsp;<A HREF="#field_summary">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: &nbsp;<A HREF="#field_detail">FIELD</A>&nbsp;|&nbsp;CONSTR&nbsp;|&nbsp;<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 + -