Note that there are some explanatory texts on larger screens.

plurals
  1. POForcing socket.connect to wait a specific time before it decides a connection is unavailable
    text
    copied!<p>I'm issuing a socket connection, using the following snippet</p> <pre><code> Socket socket = new Socket(); InetSocketAddress endPoint = new InetSocketAddress("localhost", 1234); try { socket.connect(endPoint, 30000); } catch (IOException e) { e.printStackTrace(); // Logging } </code></pre> <p>The endpoint it is trying to connect to is offline, what I want it to do is to attempt to connect, and using the <code>30000</code>ms timeout, wait for that period of time before it concludes a result</p> <p>Currently, that <code>30000</code> parameter doesn't seem to be applied, as from the timestamp on my logging it appears that it is determining within 1 second that a connection failed.</p> <p>How can I force the connect to wait for a set amount of time before giving up?</p> <pre><code>13:13:57,685 6235 DEBUG [Thread-7] - Unable to connect to [localhost:1234] 13:13:58,685 7235 DEBUG [Thread-7] - Unable to connect to [localhost:1234] 13:13:59,695 8245 DEBUG [Thread-7] - Unable to connect to [localhost:1234] 13:14:00,695 9245 DEBUG [Thread-7] - Unable to connect to [localhost:1234] </code></pre> <p>EDIT : The <a href="http://download.oracle.com/javase/1.4.2/docs/api/java/net/Socket.html#connect%28java.net.SocketAddress,%20int%29" rel="nofollow">API</a> does state <code>Connects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.</code> however it appears I'm not experiencing such behaviour, or am not catering to it, most likely the latter</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload