Socket connect timeouts: where is the specification?

前端 未结 2 1448
鱼传尺愫
鱼传尺愫 2021-02-10 08:15

The context of my work is my local area network.

The code samples below are written in Java language but my question is about TCP, not programming.

I have experi

2条回答
  •  余生分开走
    2021-02-10 08:40

    As you have found out, you can specify a timeout in the connect(...) method call as such:

    connect( SocketAddress endpoint , int timeout )
    

    And remember that "...A timeout of zero is interpreted as an infinite timeout." (where "infinite" often really means "use the OS default").

    As for the defaults, they are OS dependent, but usually fairly consistent anyways. If you're on a linux box, have a look at /proc/sys/net/ipv4/tcp_keepalive* (but don't change them unless you know what you're doing :-)

    Cheers,

提交回复
热议问题