I am trying to sort through a list of SOCKS proxies, and figure out which ones have a connect and read time of less than 1000ms, here is my code
for(Proxy p : proxies) {
try {
URLConnection testConnection = testUrl.openConnection(p);
testConnection.setConnectTimeout(TIMEOUT_VALUE);
testConnection.setReadTimeout(TIMEOUT_VALUE);
success.add(p);
} catch(SocketTimeoutException ste) {
System.out.println("Proxy " + p.address().toString() + " timed out.");
}
}
But every single one of them passes the test, even when I do TIMEOUT_VALUE = 1;
What am I doing wrong? Thanks for any help.
I use
I assume your problem is you don't read anything from connection. If I set
TIMEOUT_VALUE
too low, I get an exception. Whether I read all response or only one line did not affect the resulting time, I guess it is because I got whole answer in one packet.Here is the measurement I used (without proxies):