0

Socket: Connect spends 2 minutes looking for IP before it timesOut. I want to reduce that time to 10-15 seconds.

For connection I am using following code....

public static boolean available (String host, String port){
    try {
          Socket s = new Socket (host, port);
          return true;
       }
    catch (Exception e) {
       return false;
    }
}

How do I minimize timeout time to 10-15 seconds instead of 2 minutes? Is there any method to do that or any other alternate way?

1
  • @Neel If you know it then only answer..... Commented Jan 3, 2014 at 10:46

1 Answer 1

2

You don't set a timeout for the socket, you set a timeout for the operations you perform on that socket.

For example socket.connect(otherAddress, timeout)

Or socket.setSoTimeout(timeout) for setting a timeout on read() operations.

See: http://download.oracle.com/javase/1.4.2/docs/api/java/net/Socket.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.