JAVA Socket的方法說明

 Java代碼 複製代碼 收藏代碼java

  1. /**
  2. * Enable/disable TCP_NODELAY (disable/enable Nagle's algorithm).
  3. *
  4. * @param on <code>true</code> to enable TCP_NODELAY,
  5. * <code>false</code> to disable.
  6. *
  7. * @exception SocketException if there is an error
  8. * in the underlying protocol, such as a TCP error.
  9. *
  10. * @since JDK1.1
  11. *
  12. * @see #getTcpNoDelay()
  13. */
  14. public void setTcpNoDelay(boolean on) throws SocketException
  • setTcpNoDelay

這是一個設置是否啓用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

 

Java代碼 複製代碼 收藏代碼
  1. /**
  2. * Send one byte of urgent data on the socket. The byte to be sent is the lowest eight
  3. * bits of the data parameter. The urgent byte is
  4. * sent after any preceding writes to the socket OutputStream
  5. * and before any future writes to the OutputStream.
  6. * @param data The byte of data to send
  7. * @exception IOException if there is an error
  8. * sending the data.
  9. * @since 1.4
  10. */
  11. public void sendUrgentData (int data) throws IOException

 

  • sendUrgentData

設置緊急數據包——在socket上發送一個byte的緊急數據,它會在全部socket的輸出流(OutputStream),已經寫入以後,可是在其餘將要發送的數據以前。spa

一般,發送緊急數據用於處理一些特殊狀況。(如通知對方執行某個控制指令)。.net

Java代碼 複製代碼 收藏代碼
  1. /**
  2. * Enable/disable SO_TIMEOUT with the specified timeout, in
  3. * milliseconds. With this option set to a non-zero timeout,
  4. * a read() call on the InputStream associated with this Socket
  5. * will block for only this amount of time. If the timeout expires,
  6. * a <B>java.net.SocketTimeoutException</B> is raised, though the
  7. * Socket is still valid. The option <B>must</B> be enabled
  8. * prior to entering the blocking operation to have effect. The
  9. * timeout must be > 0.
  10. * A timeout of zero is interpreted as an infinite timeout.
  11. * @param timeout the specified timeout, in milliseconds.
  12. * @exception SocketException if there is an error
  13. * in the underlying protocol, such as a TCP error.
  14. * @since JDK 1.1
  15. * @see #getSoTimeout()
  16. */
  17. public synchronized void setSoTimeout(int timeout) throws SocketException  
相關文章
相關標籤/搜索