How does the socket connect timeout work?
Asked Answered
C

1

6

To my understanding, the socket connection timeout is controlled by the TCP transport, which uses Retransmission Timeouts (RTOs). if the the ack does not come back before timer expires, the connect request (Sync) will be retransmitted, and the RTO will be doubled.

So what is the functionality of connection timeout in Java socket when we call Socket.connect(endpoint, connectTimeout)

Cocke answered 12/4, 2011 at 3:45 Comment(0)
A
5

So what is the functionality of connection timeout in Java socket when we call Socket.connect(endpoint, connectTimeout)

It sets an overall timeout for the connection to have been established; i.e. it says how long the application is prepared to wait for all of the packet-level timeouts, retransmissions, etc to succeed (or not) before giving up.

Aeroplane answered 12/4, 2011 at 4:43 Comment(3)
That is also what I am guessing, but do you have a reference for this? Also, if we do not explicitly set the timeout when we try to connect, after how many retries, tcp will give up the connection setup?Cocke
This is specified in the Socket.connect(...) javadoc. The number of retries and the interval between them is determined by the OS implementation of TCP/IP, and Java doesn't provide a way either find out what these values are, or change them. (There's no need.)Aeroplane
Documentation does not describe connectTimeout=0, which is the default value in constructor overload Socket(endpoint); the semantics certainly is not ´overall timeout = 0ms´Mcgee

© 2022 - 2024 — McMap. All rights reserved.