When connecting to a server with a Java client socket I had this two different connection timeout exceptions.
Caused by: java.net.SocketTimeoutException: con
ConnectException is thrown on packet filter/firewall etc.
SocketTimeoutException is thrown when you have set a specific timeout on your socket, and it has not received anything before the timeout.
Example with a ServerSocket
:
ServerSocket serverSocket = new ServerSocket... // Create server socket
serverSocket.setSoTimeout(1000);
serverSocket.accept();
If the ServerSocket
has not received anything within 1000 ms it will throw a SocketTimeoutException
. Note that this exception is thrown for all sockets that use timeouts, not only ServerSocket
. This means that a Socket
object that throws a SocketTimeoutException
hasn't got anything back from the called server before the timeout.
To fix the problem you can either make sure that the server responds quicker, or set a higher timeout value.