title: Java socket connection timed out, works on local
body: <p>The code in question is this:</p>
  
  <pre><code>class Server {
      public static void main(String[] args) {
          try {
              ServerSocket ss = new ServerSocket(4001);
              Socket s = ss.accept();
              // streams, buffer, strings, main loop and socket closing; all works fine
          }catch(Exception e) {/*handle*/}
      }
  }
  
  class Client {
      public static void main(String[] args) {
          try {
              Socket s = new Socket(InetAddress.getByName("24.135.22.219"), 4001); // &lt;&lt; Connection fails here.
              // streams, buffer, strings, main loop and socket closing; all works fine
          }catch(Exception e) {/*handle*/}
      }
  }
  </code></pre>
  
  <p>It all works fine on local, when <code>"serverIP"</code> is replaced with <code>InetAddress.getByName(null)</code>. However, when it's replaced with my IP address, the connection isn't made (even though I disable the Windows Firewall) and I get a <code>Connection timed out</code> error.</p>
  
  <p>Files for testing are <a href="https://www.dropbox.com/sh/398j8f2exxrxtjb/AADAqRi01MZAKrMaRPkebeLQa?dl=0" rel="nofollow">here</a>.</p>