📄 socket.html
字号:
<BR> Gets the value of the SO_RCVBUF option for this <tt>Socket</tt>, that is the buffer size used by the platform for input on this <tt>Socket</tt>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#getSendBufferSize()">getSendBufferSize</A></B>()</CODE><BR> Get value of the SO_SNDBUF option for this <tt>Socket</tt>, that is the buffer size used by the platform for output on this <tt>Socket</tt>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#getSoLinger()">getSoLinger</A></B>()</CODE><BR> Returns setting for SO_LINGER.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> int</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#getSoTimeout()">getSoTimeout</A></B>()</CODE><BR> Returns setting for SO_TIMEOUT.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> boolean</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#getTcpNoDelay()">getTcpNoDelay</A></B>()</CODE><BR> Tests if TCP_NODELAY is enabled.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#setKeepAlive(boolean)">setKeepAlive</A></B>(boolean on)</CODE><BR> Enable/disable SO_KEEPALIVE.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#setReceiveBufferSize(int)">setReceiveBufferSize</A></B>(int size)</CODE><BR> Sets the SO_RCVBUF option to the specified value for this <tt>Socket</tt>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#setSendBufferSize(int)">setSendBufferSize</A></B>(int size)</CODE><BR> Sets the SO_SNDBUF option to the specified value for this <tt>Socket</tt>.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>static void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#setSocketImplFactory(java.net.SocketImplFactory)">setSocketImplFactory</A></B>(<A HREF="../../java/net/SocketImplFactory.html">SocketImplFactory</A> fac)</CODE><BR> Sets the client socket implementation factory for the application.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#setSoLinger(boolean, int)">setSoLinger</A></B>(boolean on, int linger)</CODE><BR> Enable/disable SO_LINGER with the specified linger time in seconds.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#setSoTimeout(int)">setSoTimeout</A></B>(int timeout)</CODE><BR> Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#setTcpNoDelay(boolean)">setTcpNoDelay</A></B>(boolean on)</CODE><BR> Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#shutdownInput()">shutdownInput</A></B>()</CODE><BR> Places the input stream for this socket at "end of stream".</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#shutdownOutput()">shutdownOutput</A></B>()</CODE><BR> Disables the output stream for this socket.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../java/lang/String.html">String</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../java/net/Socket.html#toString()">toString</A></B>()</CODE><BR> Converts this socket to a <code>String</code>.</TD></TR></TABLE> <A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor"><TD><B>Methods inherited from class java.lang.<A HREF="../../java/lang/Object.html">Object</A></B></TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><A HREF="../../java/lang/Object.html#clone()">clone</A>, <A HREF="../../java/lang/Object.html#equals(java.lang.Object)">equals</A>, <A HREF="../../java/lang/Object.html#finalize()">finalize</A>, <A HREF="../../java/lang/Object.html#getClass()">getClass</A>, <A HREF="../../java/lang/Object.html#hashCode()">hashCode</A>, <A HREF="../../java/lang/Object.html#notify()">notify</A>, <A HREF="../../java/lang/Object.html#notifyAll()">notifyAll</A>, <A HREF="../../java/lang/Object.html#wait()">wait</A>, <A HREF="../../java/lang/Object.html#wait(long)">wait</A>, <A HREF="../../java/lang/Object.html#wait(long, int)">wait</A></CODE></TD></TR></TABLE> <P><!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><A NAME="constructor_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%"><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TD COLSPAN=1><FONT SIZE="+2"><B>Constructor Detail</B></FONT></TD></TR></TABLE><A NAME="Socket()"><!-- --></A><H3>Socket</H3><PRE>protected <B>Socket</B>()</PRE><DL><DD>Creates an unconnected socket, with the system-default type of SocketImpl.<DD><DL><DT><B>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="Socket(java.net.SocketImpl)"><!-- --></A><H3>Socket</H3><PRE>protected <B>Socket</B>(<A HREF="../../java/net/SocketImpl.html">SocketImpl</A> impl) throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Creates an unconnected Socket with a user-specified SocketImpl. <P><DD><DL><DT><B>Parameters:</B><DD><CODE>impl</CODE> - an instance of a <B>SocketImpl</B> the subclass wishes to use on the Socket.<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>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="Socket(java.lang.String, int)"><!-- --></A><H3>Socket</H3><PRE>public <B>Socket</B>(<A HREF="../../java/lang/String.html">String</A> host, int port) throws <A HREF="../../java/net/UnknownHostException.html">UnknownHostException</A>, <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Creates a stream socket and connects it to the specified port number on the named host. <p> If the application has specified a server socket factory, that factory's <code>createSocketImpl</code> method is called to create the actual socket implementation. Otherwise a "plain" socket is created. <p> If there is a security manager, its <code>checkConnect</code> method is called with the host address and <code>port</code> as its arguments. This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>host</CODE> - the host name.<DD><CODE>port</CODE> - the port number.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/net/UnknownHostException.html">UnknownHostException</A></CODE> - if the IP address of the host could not be determined.<DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O error occurs when creating the socket.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkConnect</code> method doesn't allow the operation.<DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setSocketImplFactory(java.net.SocketImplFactory)"><CODE>setSocketImplFactory(java.net.SocketImplFactory)</CODE></A>, <A HREF="../../java/net/SocketImpl.html"><CODE>SocketImpl</CODE></A>, <A HREF="../../java/net/SocketImplFactory.html#createSocketImpl()"><CODE>SocketImplFactory.createSocketImpl()</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><HR><A NAME="Socket(java.net.InetAddress, int)"><!-- --></A><H3>Socket</H3><PRE>public <B>Socket</B>(<A HREF="../../java/net/InetAddress.html">InetAddress</A> address, int port) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Creates a stream socket and connects it to the specified port number at the specified IP address. <p> If the application has specified a socket factory, that factory's <code>createSocketImpl</code> method is called to create the actual socket implementation. Otherwise a "plain" socket is created. <p> If there is a security manager, its <code>checkConnect</code> method is called with the host address and <code>port</code> as its arguments. This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>address</CODE> - the IP address.<DD><CODE>port</CODE> - the port number.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O error occurs when creating the socket.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkConnect</code> method doesn't allow the operation.<DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setSocketImplFactory(java.net.SocketImplFactory)"><CODE>setSocketImplFactory(java.net.SocketImplFactory)</CODE></A>, <A HREF="../../java/net/SocketImpl.html"><CODE>SocketImpl</CODE></A>, <A HREF="../../java/net/SocketImplFactory.html#createSocketImpl()"><CODE>SocketImplFactory.createSocketImpl()</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><HR><A NAME="Socket(java.lang.String, int, java.net.InetAddress, int)"><!-- --></A><H3>Socket</H3><PRE>public <B>Socket</B>(<A HREF="../../java/lang/String.html">String</A> host, int port, <A HREF="../../java/net/InetAddress.html">InetAddress</A> localAddr, int localPort) throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Creates a socket and connects it to the specified remote host on the specified remote port. The Socket will also bind() to the local address and port supplied. <p> If there is a security manager, its <code>checkConnect</code> method is called with the host address and <code>port</code> as its arguments. This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>host</CODE> - the name of the remote host<DD><CODE>port</CODE> - the remote port<DD><CODE>localAddr</CODE> - the local address the socket is bound to<DD><CODE>localPort</CODE> - the local port the socket is bound to<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O error occurs when creating the socket.<DD><CODE><A HREF="../../java/lang/SecurityException.html">SecurityException</A></CODE> - if a security manager exists and its <code>checkConnect</code> method doesn't allow the operation.<DT><B>Since: </B><DD>JDK1.1</DD><DT><B>See Also: </B><DD><A HREF="../../java/lang/SecurityManager.html#checkConnect(java.lang.String, int)"><CODE>SecurityManager.checkConnect(java.lang.String, int)</CODE></A></DL></DD></DL><HR><A NAME="Socket(java.net.InetAddress, int, java.net.InetAddress, int)"><!-- --></A><H3>Socket</H3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -