Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Socket Connection Timeout issue

843790Dec 28 2006 — edited Dec 29 2006
Can anyone explain how I can get a ConnectionException that states as the reason "conntection timed out" when I try to connect a socket without setting the timeout parameter?

socket = new Socket();
SocketAddress sAddr = new InetSocketAddress(host, port);
socket.connect( sAddr );

gives me:
java.net.ConnectException: Connection timed out

Comments

EJP
That can happen if there is no response whatsoever from the target system. The client will send a TCP SYN segment and expect a TCP SYN-ACK segment in reply, or in the case of error an ICMP error packet (e.g. 'connection refused'). If it doesn't get either of these within its timeout it retries with double the timeout. It does this so many times, totalling a timeout of around 75 seconds, then you get your timeout message.
If it doesn't get either
of these within its timeout it retries with double
the timeout. It does this so many times, totalling a
timeout of around 75 seconds, then you get your
timeout message.
I thought normal connection timeouts were between 2 minutes and 5 minutes?

Or perhaps I am confusing that with the default send timeout?
EJP
Nope. As an example, on Windows there are three retries with an initial timeout of 6 seconds and exponential backoff on retry. So the total timeout is 6+12+24=42 seconds. The Unix/Linux algorithms are different, but they generally adds up to about 75 seconds. You don't need 5 minutes for acknowledging a SYN segment at the kernel level.
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jan 26 2007
Added on Dec 28 2006
3 comments
454 views