ConnectException: operation timed out
<p>I have the following class that opens a socket connection to query a WHOIS server. Unfortunately, every time I run it (e.g. java WHOIS google.com) it always throws the exception:</p>

<p><strong>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.(Socket.java:375)
    at java.net.Socket.(Socket.java:189)
    at WHOIS.performWhoisQuery(WHOIS.java:11)
    at WHOIS.main(WHOIS.java:28)</strong></p>

<p>The problem seems connection timeout and i tried setting the timeout to a longer value (e.g. 5000) and it didn't work. Does it have to do with proxy and/or firewall? I got stuck whole day on it. </p>

<pre><code>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);

}
</code></pre>

<p>}</p>
