Reputation: 597
I am trying to check wether proxy servers are working. I'm using this code, but it doesn't seem to be working correctly. It returns true, but when i try to use the proxy, the program times out.
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("ip", port));
int timeout = 9000;
URL url = new URI("http://google.com/").toURL();
URLConnection connection = url.openConnection(proxy);
connection.setConnectTimeout((int) timeout);
connection.setReadTimeout((int) timeout);
long start = System.currentTimeMillis();
connection.connect();
long delay = System.currentTimeMillis() - start;
return delay <= timeout;
Thanks
Upvotes: 1
Views: 2962
Reputation: 311055
Just try to use the proxy in the normal way as you need it, and handle the exceptions as they arise.
Tricks like this are essentially attempts to predict the future. They cannot possibly work.
Upvotes: 2