/** * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm). * * @param on <code>true</code> to enable TCP_NODELAY, * <code>false</code> to disable. * * @exception SocketException if there is an error * in the underlying protocol, such as a TCP error. * * @since JDK1.1 * * @see #getTcpNoDelay() */ public void setTcpNoDelay(boolean on) throws SocketException
这是一个设置是否启用Nagle算法,Nagle算法是一个TCP层的通讯流量的拥塞控制算法(Flow Control),在大学的计算机网络课本上都会提到这个慢启动(Slow start)”和“拥塞避免(Congestion avoidance)”,“快速重传(Fast retransmit)”、“快速恢复(Fast Recovery)”。算法
缺省的算法实现通常都是启用的。这样能够处理,防止发送方处理过快,接受方数据处理不过来的状况。可是,若是在实时处理上,一般发送方不须要关心接收方是否可以及时处理数据,所以可能须要设置这个参数。、网络
若是设置ture,不启用Nagle‘s algorithmsocket
若是为false,启用Nagle's algorithmide
缺省值,依赖于socket的具体实现,一般是false。即启用Naglethis
-----------------------------------------------------------------------------------------------------------url
/** * Send one byte of urgent data on the socket. The byte to be sent is the lowest eight * bits of the data parameter. The urgent byte is * sent after any preceding writes to the socket OutputStream * and before any future writes to the OutputStream. * @param data The byte of data to send * @exception IOException if there is an error * sending the data. * @since 1.4 */ public void sendUrgentData (int data) throws IOException
设置紧急数据包——在socket上发送一个byte的紧急数据,它会在全部socket的输出流(OutputStream),已经写入以后,可是在其余将要发送的数据以前。spa
一般,发送紧急数据用于处理一些特殊状况。(如通知对方执行某个控制指令)。.net
/** * 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.net.SocketTimeoutException</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. * @param timeout the specified timeout, in milliseconds. * @exception SocketException if there is an error * in the underlying protocol, such as a TCP error. * @since JDK 1.1 * @see #getSoTimeout() */ public synchronized void setSoTimeout(int timeout) throws SocketException