如何检查 Java 中的代理是否正常工作?
我搜索了 google、这个网站和 JavaRanch,但找不到答案。
我的程序需要从选定的文件中获取代理(我使用 java gui FileChooser 类和 RandomAccessFile 完成了该操作)
然后我需要从 txt 文件中第一个文件开始验证代理。它将尝试连接到某个站点或端口以验证连接是否成功。如果连接成功(我得到了肯定的响应),它将将该代理添加到代理列表中,然后获取并检查列表中的下一个直到完成。
我知道该怎么做,但我遇到了一个小问题。我的问题是这个过程需要独立于连接速度,因为有人可能为要处理的连接设置 15000(毫秒)超时并设置 100 个线程,然后由于连接太慢,所有代理都不会工作。
我听说过一种叫做 ping 的方法来检查代理,但我不知道如何在 java 中使用它。
谁能给我解决方案或至少我可以使用的课程。
I searched google, this site and JavaRanch and I can not find an answer.
My program needs to obtain proxies from a selected file(I got that done using java gui FileChooser class and RandomAccessFile)
Then I need to verify the proxies starting with the one that is first in the txt file. It will try to connect to some site or port to verify if the connection was successful.If the connection was successful (I got a positive response) it will add the proxy to a list of proxies and then get and check next one in the list until it is done.
I know how to do this but I got a little problem. My Problem is that this process needs to be independent of connection speed because someone may set 15000(milliseconds) timeout for the connection to be dealt with and set 100 threads and then none of the proxies would come out working because connection is too slow.
I heard of a method called pinging to check proxies,but I do not know how to use it in java.
Could anyone give me solution or at least classes I could use.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了一个解决方案,而且很简单。
我使用了
InetAddress.isReachable()
方法以及 Apache 的一些HttpClient
。对于代理检查,我使用了blanksite.com
因为我需要的是检查可连接性而不是代理的速度。所以这里是代码(包括来自文件的输入,但它还不是 gui):
Ok I found a solution and it is easy.
What I used it
InetAddress.isReachable()
method along with someHttpClient
by Apache. For proxy checking I usedblanksite.com
because all I need is check connectability and not speed of proxies.So here is the code(Including input from file, but it is not gui, YET):