/** * 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