0
我有以下類打開套接字連接來查詢WHOIS服務器。不幸的是,我每次運行它(例如,Java WHOIS google.com)它總是拋出異常:ConnectException:操作超時
Contacting the WHOIS server for 'google.com' at whois.internic.net:43
Exception in thread "main" java.net.ConnectException: Operation timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at WHOIS.performWhoisQuery(WHOIS.java:11)
at WHOIS.main(WHOIS.java:28)
這個問題似乎連接超時,我試圖超時設置更長的值(例如5000),它沒沒有工作。它是否與代理和/或防火牆有關?我一整天都被卡住了。
public class WHOIS {
public static void performWhoisQuery(String host, int port, String query) throws Exception {
System.out.println(" Contacting the WHOIS server for '" + query + "' at " + host + ":" + port);
Socket socket = new Socket(host, port);
InputStreamReader isr = new InputStreamReader(socket.getInputStream());
BufferedReader br = new BufferedReader(isr);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println(query);
String aLine = "";
while ((aLine = br.readLine()) != null) {
System.out.println(aLine);
}
}
public static void main(String[] args) throws Exception {
String domainNameToCheck = args[0];
performWhoisQuery("whois.internic.net", 43, domainNameToCheck);
}
}
謝謝! telnet也會因連接超時而終止。好吧,那麼它必須處理防火牆的限制。我會嘗試從不同的環境。 – 2011-03-25 17:22:38
@Birhanu Mekuria Eshete是的,但它先連接然後超時,還是不能完全連接? – NPE 2011-03-25 17:24:32
它根本沒有連接。它終止於:「嘗試199.7.52.74 ... telnet:連接到地址199.7.52.74:操作超時 telnet:無法連接到遠程主機」 「 – 2011-03-25 18:08:06