TCP的几个常用参数

 

 

 

SO_LINGER

Specify a linger-on-close timeout. This option disables/enables immediate return from a close()of a TCP Socket.  Enabling this option with a non-zero Integer timeout  means that a close() will block pending the transmission and acknowledgement of all data written to the peer, at which point the socket is closed gracefully. Upon reaching the linger timeout, the socket is closed forcefully, with a TCP RST. Enabling the option with a timeout of zero does a forceful close immediately. If the specified timeout value exceeds 65,535 it will be reduced to 65,535.

SO_TIMEOUT

Set a timeout on blocking Socket operations:

     * <PRE>

     * ServerSocket.accept();

     * SocketInputStream.read();

     * DatagramSocket.receive();

     * </PRE>

The option must be set prior to entering a blocking operation to take effect. If the timeout expires and the operation would continue to block, <B>java.io.InterruptedIOException</B> is raised.  The Socket is not closed in this case.

SO_SNDBUF

Set a hint the size of the underlying buffers used by the platform for outgoing network I/O. When used in set, this is a suggestion to the kernel from the application about the size of buffers to use for the data to be sent over the socket. When used in get, this must return the size of the buffer actually used by the platform when sending out data on this socket.

SO_RCVBUF

Set a hint the size of the underlying buffers used by the platform for incoming network I/O. When used in set, this is a suggestion to the kernel from the application about the size of buffers to use for the data to be received over the

socket. When used in get, this must return the size of the buffer actually used by the platform when receiving in data on

 this socket.

SO_KEEPALIVE

When the keepalive option is set for a TCP socket and no data has been exchanged across the socket in either direction for  2 hours (NOTE: the actual value is implementation dependent),

     * TCP automatically sends a keepalive probe to the peer. This probe is a TCP segment to which the peer must respond.

     * One of three responses is expected:

     * 1. The peer responds with the expected ACK. The application is not    notified (since everything is OK). TCP will send another probe following another 2 hours of inactivity.

     * 2. The peer responds with an RST, which tells the local TCP that the peer host has crashed and rebooted. The socket is closed.

     * 3. There is no response from the peer. The socket is closed.

     * The purpose of this option is to detect if the peer host crashes.

SO_REUSEADDR

Used by MulticastSockets

TCP_NODELAY

Disable Nagle's algorithm for this connection.  Written data to the network is not buffered pending acknowledgement of previously written data

public void connect(SocketAddress endpoint, int timeout)

 

    

 

Nagle's algorithmhttp://en.wikipedia.org/wiki/Nagle's_algorithm

Socket-faq: ftp://rtfm.mit.edu/pub/usenet/news.answers/unix-faq/socket

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值