title: RMI does not return response over internet
body: <p>I have a simple rmi-server and rmi-client. When i run this server and client in same network, my server function returns the result properly. But my server and client are in different networks and if the process time is more than 3-4 minutes client can not get the result, although server fihishes the operation.</p>
  <p>here is my entire server code:</p>
  <pre><code>public class SimpleServer {
  
      ServerRemoteObject mRemoteObject;
  
      public static int RMIInPort = 27550;
      public static int delay = 0;
      
      public byte[] handleEvent(byte[] mMessage) throws Exception {
  
          String request = new String(mMessage, &quot;UTF-8&quot;);
  
  //      if (&quot;hearthbeat&quot;.equalsIgnoreCase(request)) {
  //          System.out.println(&quot;returning for hearthbeat&quot;);
  //          return &quot;hearthbeat response&quot;.getBytes(&quot;UTF-8&quot;);
  //      }
  
          System.out.println(request);
  
          Thread.sleep(delay);
  
          System.out.println(&quot;returning response&quot;);
          return &quot;this is response&quot;.getBytes(&quot;UTF-8&quot;);
      }
      
      public void bindYourself(int rmiport) {
          try {
              mRemoteObject = new ServerRemoteObject(this);
              java.rmi.registry.Registry iRegistry = LocateRegistry.getRegistry(rmiport);
              iRegistry.rebind(&quot;Server&quot;, mRemoteObject);
          } catch (Exception e) {
              e.printStackTrace();
              mRemoteObject = null;
          }
      }
  
      public static void main(String[] server) {
  
          int rmiport = Integer.parseInt(server[0]);
          RMIInPort = Integer.parseInt(server[1]);
          delay = Integer.parseInt(server[2]);
  
          System.out.println(&quot;server java:&quot; + System.getProperty(&quot;java.version&quot;));
          System.out.println(&quot;server started on:&quot; + rmiport + &quot;/&quot; + RMIInPort);
          System.out.println(&quot;server delay on:&quot; + delay);
  
          SimpleServer iServer = new SimpleServer();
          iServer.bindYourself(rmiport);
  
          while (true) {
              try {
                  Thread.sleep(10000);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  
  }
  </code></pre>
  <p>and here is my client code:</p>
  <pre><code>public class SimpleClient {
  
      ISimpleServer iServer;
  
      public SimpleClient(String p_strServerIp, String p_strCMName, int nRMIPort) {
          try {
              if (nRMIPort == 1099) {
                  iServer = (ISimpleServer) Naming.lookup(&quot;rmi://&quot; + p_strServerIp + &quot;/&quot; + p_strCMName);
              } else {
                  Registry rmiRegistry = null;
  
                  rmiRegistry = LocateRegistry.getRegistry(p_strServerIp, nRMIPort);
  
                  iServer = (ISimpleServer) rmiRegistry.lookup(p_strCMName);
              }
          } catch (Exception ex) {
              ex.printStackTrace();
              iServer = null;
          }
      }
  
      public static void main(String... strings) {
  
          String ip = strings[0];
          int rmiport = Integer.parseInt(strings[1]);
  
          System.out.println(&quot;client java:&quot; + System.getProperty(&quot;java.version&quot;));
          System.out.println(&quot;client is looking for:&quot; + ip + &quot;:&quot; + rmiport);
  
          SimpleClient iClient = new SimpleClient(ip, &quot;Server&quot;, rmiport);
  
          try {
  
              byte[] response = iClient.iServer.doaction(&quot;this is request&quot;.getBytes(&quot;UTF-8&quot;));
  
              System.out.println(new String(response, &quot;UTF-8&quot;));
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  <p>and here is my rmi-registry code:</p>
  <pre><code>public class SimpleRMI implements Runnable {
  
      Registry mRegistry = null;
  
      public SimpleRMI(int nPort) {
          try {
              mRegistry = new sun.rmi.registry.RegistryImpl(nPort);
          } catch (RemoteException e1) {
              e1.printStackTrace();
          }
      }
  
      @Override
      public void run() {
          while (true) {
              try {
                  Thread.sleep(360000);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  
      public static void main(String... strings) {
          
          int rmiport = Integer.parseInt(strings[0]);
          
          System.out.println(&quot;rmi java:&quot; + System.getProperty(&quot;java.version&quot;));
          System.out.println(&quot;rmi started on:&quot; + rmiport);
  
          SimpleRMI iRegisry = new SimpleRMI(rmiport);
  
          Thread tThread = new Thread(iRegisry);
  
          tThread.start();
  
          byte[] bytes = new byte[1];
          while (true) {
              try {
                  System.in.read(bytes);
                  if (bytes[0] == 13) {
                      try {
                          iRegisry.listRegistry();
                      } catch (Exception exc2) {
                          exc2.printStackTrace();
                      }
                  }
              } catch (Exception exc) {
                  exc.printStackTrace();
              }
          }
  
      }
  
      private void listRegistry() {
  
          String[] strList = null;
          try {
              strList = mRegistry.list();
              if (strList != null) {
                  for (int i = 0; i &lt; strList.length; i++) {
                      int j = i + 1;
                      String name = strList[i];
                      java.rmi.Remote r = mRegistry.lookup(name);
                      System.out.println(j + &quot;. &quot; + strList[i] + &quot; -&gt; &quot;
                              + r.toString());
                  }
              }
              System.out.println();
          } catch (Exception exc) {
              exc.printStackTrace();
          }
  
      }
  }
  </code></pre>
  <p>and my remote interface and remote object:</p>
  <pre><code>public interface ISimpleServer extends java.rmi.Remote {
  
      public byte[] doaction(byte[] message) throws java.rmi.RemoteException;
  }
  
  @SuppressWarnings(&quot;serial&quot;)
  public class ServerRemoteObject extends UnicastRemoteObject implements ISimpleServer {
  
      SimpleServer Server = null;
  
      public ServerRemoteObject(SimpleServer pServer) throws RemoteException {
          super(SimpleServer.RMIInPort);
          Server = pServer;
      }
  
      @Override
      public byte[] doaction(byte[] message) throws RemoteException {
          try {
              return Server.handleEvent(message);
          } catch (Exception e) {
              e.printStackTrace();
              return null;
          }
      }
  
  }
  </code></pre>
  <p>when i run client and server in different networks. (i run client in my home network) and if delay is more than 3-4 mins server prints <strong>returning response</strong> but client still waits for the response. If delay is only 1 minute, clients gets the result properly.</p>
  <p>Can you please help me to find where the problem is?</p>