I have the following code:
socket.connect(new InetSocketAddress(serverHost, serverPort), CONNECT_TIMEOUT);
The problem is that when DNS is not available, InetSocketAddress takes 45 seconds to time out and returns an exception ("Host in not available ..."). I need the whole command (so creating an InetSocketAddress and connecting to a timeout earlier. I have not found a way to timeout new InetSocketAddress(serverHost, serverPort) before.
Is it possible?
PS I am on Android, but the problem is the same on another platform
user1175790
source share