• 1 reply
  • Latest Post - ‏2011-10-11T08:42:35Z by VenkatRArra
4672 Posts

Pinned topic Connection Timeout

‏2010-06-09T11:56:20Z |
This is Sandeep and this thread is regarding Socket Connection TimeOut.
Lets consider the Scenario::
1. I am trying to connect to "Remote System" on some port where an Application is running.
2. By the time when I tried to connect, the Application is down.
For this I used to get " Connection refused: connect". It is fine.
3. Now I want to specify the TimeOut value where I need my application keeps on polling the port. As soon as the Application comes up in remote system within the Time frame(specified TimeOut value), my application has to connect.

I have tried the below ways... These are simple stand alone applications...But failed.. :(

InetAddress addr = InetAddress.getByName("");
int port = 9088;
SocketAddress sockaddr = new InetSocketAddress(addr, port);

Socket sock = new Socket();
int timeoutMs = 60*1000;
sock.connect(sockaddr, timeoutMs);

And also the below application

InetAddress addr = InetAddress.getByName("");
int timeout=60*1000;
Socket socket1 = new Socket();
socket1.connect(addr, 9088));

When I ran the application, it is not at all waiting for the time what I have specified (60000ms).
It is immediately throwing the " Connection refused: connect" Exception.

Eagerly waiting for the responses.
Appreciates your help.
Thnx in advance.

Updated on 2011-10-11T08:42:35Z at 2011-10-11T08:42:35Z by VenkatRArra
  • VenkatRArra
    2 Posts

    Re: Connection Timeout

    The timeout is the time to wait until connection is either success or some error occurs.

    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.

    Hence, the retry functionality should be added in java code and cannot be handled by TCP/IP.