I am connecting to a web service and did not set any connect timeout and read timeout on HttpURLConnection. What is the default connect timeout and read timeout? Is it dependent
The Javadoc for connect()
is incorrect. Zero gives you the platform connect timeout, which is not infinite, but around a minute. You can only decrease this value with the timeout
parameter to connect(),
not increase it.
If the getConnectTimeout
and getReadTimeout
from the object return zero, then that does indeed mean infinity. This is inherited from the underlying URLConnection
class.
It may be that the exception you're receiving is not a SocketTimeoutException
at all, you should verify this - it's possible to get IOException
thrown regardless of the timeout settings.
Did you do any research? The defaults are detailed in the documentation. Here's the relevant parts:
public void setConnectTimeout (int timeout) Since: API Level 1
Sets the timeout value in milliseconds for establishing the connection to the resource pointed by this URLConnection instance. A SocketTimeoutException is thrown if the connection could not be established in this time. Default is 0 which stands for an infinite timeout.
public void setReadTimeout (int timeout) Since: API Level 1
Sets the timeout value in milliseconds for reading from the input stream of an established connection to the resource. A SocketTimeoutException is thrown if the connection could not be established in this time. Default is 0 which stands for an infinite timeout.
Also there is this note on timeouts:
URLConnection supports two timeouts: a connect timeout and a read timeout. By default, operations never time out.
It might be possible that the server you are connecting to is timing out your client.