title: NoRouteToHostException in Client
body: <p>I am working on a program that involves a server and a client and I am try to listen on a port and then send messages to that port from a client. However, on doing so I get <code>NoRouteToHostException</code>. I made a simple Client and Server application to test if I can send and receive messages for my given server and client.</p>
  
  <p>Server:</p>
  
  <pre><code>public class Server{
   public static void main(String [] args) throws  Exception{
     ServerSocket s = new ServerSocket(8001);
     s.accept();
   }
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>public class Client{
    public static void main(String [] args){
      Socket s = new Socket(IP, port);
      PrintWriter p = new PrintWriter(s.getOutputStream(), true);
      p.println("Hello World");
      s.close();
    }
  }
  
  Exception in thread "main" java.net.NoRouteToHostException: No route to host
          at java.net.PlainSocketImpl.socketConnect(Native Method)
          at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
          at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
          at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
          at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
          at java.net.Socket.connect(Socket.java:589)
          at java.net.Socket.connect(Socket.java:538)
          at java.net.Socket.&lt;init&gt;(Socket.java:434)
          at java.net.Socket.&lt;init&gt;(Socket.java:211)
  </code></pre>
  
  <p>I tried to ping the server and it went through as well. Also, if I run the client on the localhost I don't get an exception. I only get the exception when the client is running on a different system.</p>
  
  <p><strong>EDIT</strong>
  When running the server on 8080, it works. I tried allowing all incoming connections to the server by doing <code>iptables --policy INPUT ACCEPT</code>, but that still doesn't allow me to listen on port 8001</p>