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

📄 socket.html

📁 API資料大全
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<PRE>public <B>Socket</B>(<A HREF="../../java/net/InetAddress.html">InetAddress</A>&nbsp;address,              int&nbsp;port,              <A HREF="../../java/net/InetAddress.html">InetAddress</A>&nbsp;localAddr,              int&nbsp;localPort)       throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Creates a socket and connects it to the specified remote address 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>address</CODE> - the remote address<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.lang.String, int, boolean)"><!-- --></A><H3>Socket</H3><PRE>public <B>Socket</B>(<A HREF="../../java/lang/String.html">String</A>&nbsp;host,              int&nbsp;port,              boolean&nbsp;stream)       throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD><B>Deprecated.</B>&nbsp;<I>Use DatagramSocket instead for UDP transport.</I><P><DD>Creates a stream socket and connects it to the specified port number on the named host. <p> If the stream argument is <code>true</code>, this creates a stream socket. If the stream argument is <code>false</code>, it creates a datagram socket. <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.<DD><CODE>stream</CODE> - a <code>boolean</code> indicating whether this is                      a stream socket or a datagram socket.<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.net.InetAddress, int, boolean)"><!-- --></A><H3>Socket</H3><PRE>public <B>Socket</B>(<A HREF="../../java/net/InetAddress.html">InetAddress</A>&nbsp;host,              int&nbsp;port,              boolean&nbsp;stream)       throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD><B>Deprecated.</B>&nbsp;<I>Use DatagramSocket instead for UDP transport.</I><P><DD>Creates a socket and connects it to the specified port number at the specified IP address. <p> If the stream argument is <code>true</code>, this creates a stream socket. If the stream argument is <code>false</code>, it creates a datagram socket. <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 <code>host.getHostAddress()</code> and <code>port</code>  as its arguments. This could result in a SecurityException.<DD><DL><DT><B>Parameters:</B><DD><CODE>host</CODE> - the IP address.<DD><CODE>port</CODE> - the port number.<DD><CODE>stream</CODE> - if <code>true</code>, create a stream socket;                       otherwise, create a datagram socket.<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><!-- ============ 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="getInetAddress()"><!-- --></A><H3>getInetAddress</H3><PRE>public <A HREF="../../java/net/InetAddress.html">InetAddress</A> <B>getInetAddress</B>()</PRE><DL><DD>Returns the address to which the socket is connected.<DD><DL><DT><B>Returns:</B><DD>the remote IP address to which this socket is connected.</DL></DD></DL><HR><A NAME="getLocalAddress()"><!-- --></A><H3>getLocalAddress</H3><PRE>public <A HREF="../../java/net/InetAddress.html">InetAddress</A> <B>getLocalAddress</B>()</PRE><DL><DD>Gets the local address to which the socket is bound.<DD><DL><DT><B>Returns:</B><DD>the local address to which the socket is bound.<DT><B>Since: </B><DD>JDK1.1</DD></DL></DD></DL><HR><A NAME="getPort()"><!-- --></A><H3>getPort</H3><PRE>public int <B>getPort</B>()</PRE><DL><DD>Returns the remote port to which this socket is connected.<DD><DL><DT><B>Returns:</B><DD>the remote port number to which this socket is connected.</DL></DD></DL><HR><A NAME="getLocalPort()"><!-- --></A><H3>getLocalPort</H3><PRE>public int <B>getLocalPort</B>()</PRE><DL><DD>Returns the local port to which this socket is bound.<DD><DL><DT><B>Returns:</B><DD>the local port number to which this socket is connected.</DL></DD></DL><HR><A NAME="getInputStream()"><!-- --></A><H3>getInputStream</H3><PRE>public <A HREF="../../java/io/InputStream.html">InputStream</A> <B>getInputStream</B>()                           throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Returns an input stream for this socket.<DD><DL><DT><B>Returns:</B><DD>an input stream for reading bytes from this socket.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O error occurs when creating the               input stream.</DL></DD></DL><HR><A NAME="getOutputStream()"><!-- --></A><H3>getOutputStream</H3><PRE>public <A HREF="../../java/io/OutputStream.html">OutputStream</A> <B>getOutputStream</B>()                             throws <A HREF="../../java/io/IOException.html">IOException</A></PRE><DL><DD>Returns an output stream for this socket.<DD><DL><DT><B>Returns:</B><DD>an output stream for writing bytes to this socket.<DT><B>Throws:</B><DD><CODE><A HREF="../../java/io/IOException.html">IOException</A></CODE> - if an I/O error occurs when creating the               output stream.</DL></DD></DL><HR><A NAME="setTcpNoDelay(boolean)"><!-- --></A><H3>setTcpNoDelay</H3><PRE>public void <B>setTcpNoDelay</B>(boolean&nbsp;on)                   throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).<DD><DL><DT><B>Parameters:</B><DD><CODE>on</CODE> - <code>true</code> to enable TCP_NODELAY,  <code>false</coder> to disable.<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><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#getTcpNoDelay()"><CODE>getTcpNoDelay()</CODE></A></DL></DD></DL><HR><A NAME="getTcpNoDelay()"><!-- --></A><H3>getTcpNoDelay</H3><PRE>public boolean <B>getTcpNoDelay</B>()                      throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Tests if TCP_NODELAY is enabled.<DD><DL><DT><B>Returns:</B><DD>a <code>boolean</code> indicating whether or not TCP_NODELAY is enabled.<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><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setTcpNoDelay(boolean)"><CODE>setTcpNoDelay(boolean)</CODE></A></DL></DD></DL><HR><A NAME="setSoLinger(boolean, int)"><!-- --></A><H3>setSoLinger</H3><PRE>public void <B>setSoLinger</B>(boolean&nbsp;on,                        int&nbsp;linger)                 throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Enable/disable SO_LINGER with the specified linger time in seconds.  The maximum timeout value is platform specific. The setting only affects socket close.<DD><DL><DT><B>Parameters:</B><DD><CODE>on</CODE> - whether or not to linger on.<DD><CODE>linger</CODE> - how to linger for, if on is true.<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.<DD><CODE><A HREF="../../java/lang/IllegalArgumentException.html">IllegalArgumentException</A></CODE> - if the linger value is negative.<DT><B>Since: </B><DD>JDK1.1</DD><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#getSoLinger()"><CODE>getSoLinger()</CODE></A></DL></DD></DL><HR><A NAME="getSoLinger()"><!-- --></A><H3>getSoLinger</H3><PRE>public int <B>getSoLinger</B>()                throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Returns setting for SO_LINGER. -1 returns implies that the option is disabled. The setting only affects socket close.<DD><DL><DT><B>Returns:</B><DD>the setting for SO_LINGER.<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><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#setSoLinger(boolean, int)"><CODE>setSoLinger(boolean, int)</CODE></A></DL></DD></DL><HR><A NAME="setSoTimeout(int)"><!-- --></A><H3>setSoTimeout</H3><PRE>public void <B>setSoTimeout</B>(int&nbsp;timeout)                  throws <A HREF="../../java/net/SocketException.html">SocketException</A></PRE><DL><DD>Enable/disable SO_TIMEOUT with the specified timeout, in  milliseconds.  With this option set to a non-zero timeout,  a read() call on the InputStream associated with this Socket  will block for only this amount of time.  If the timeout expires,  a <B>java.io.InterruptedIOException</B> is raised, though the  Socket is still valid. The option <B>must</B> be enabled  prior to entering the blocking operation to have effect. The  timeout must be > 0.  A timeout of zero is interpreted as an infinite timeout.<DD><DL><DT><B>Parameters:</B><DD><CODE>timeout</CODE> - the specified timeout, in milliseconds.<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>JDK 1.1</DD><DT><B>See Also: </B><DD><A HREF="../../java/net/Socket.html#getSoTimeout()"><CODE>getSoTimeout()</CODE></A></DL></DD></DL><HR><A NAME="getSoTimeout()"><!-- --></A><H3>getSoTimeout</H3><PRE>public int <B>getSoTimeout</B>()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -