title: Connecting with public ip in RMI
body: <p>I had written a RMI client/server program in which  Server simply reads properties from file and give it to the client. The server and client programs both reside on my machine. Sample code for server is</p>
  
  <pre><code>public class DirectoryStructure {
  
  @SuppressWarnings("deprecation")
  public static void main(String[] args) {
      System.setProperty("java.rmi.server.hostname", "local ip");
      System.setSecurityManager(new RMISecurityManager());
      DirectoryOperations directoryOperations;
      try {
          directoryOperations = new DirectoryOperations();
  
          Naming.rebind("rmi://local ip/ABC", directoryOperations);
  
          directoryOperations.addAddess("name",
                  "addeess");
          System.out.println("Directory Server is ready.");
      } catch (RemoteException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>As you can see in the rebind method when i pass my <strong>local ip</strong>  i am able to start the server successfully.When i replace this local ip with my machine's <strong>public ip</strong> i am not able to connect i get <code>java.net.ConnectException: Connection refused: connect</code>. Can anyone suggest how to start server using public ip ?</p>