Java RMI AWS two machine












0















I have two machines:



Server: AWS - EC2 - Ubuntu 18.04 Lts



Client: Windows 10



If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine



Code:



AloMundoServidor.java



import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;

public class AloMundoServidor implements AloMundo {
private static int count, fila = 0;
private static boolean lock;

public AloMundoServidor() {}

public String digaAloMundo() throws Exception {
System.out.println("Chamada de aplicacao Cliente recebida! " + count);
/*fila++;
if(lock){
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
//Log.error("Thread interrupted", e);
}
}
lock = true;
*/
File file = new File("test.txt");

BufferedReader reader = new BufferedReader(new FileReader(file));

String text = "", line;
while ((line = reader.readLine()) != null) {
text = text + "n" + line;
}

count++;
Thread.sleep(5000);

// fila--;
// notify();
// if(fila==0) {
// lock = false;
// }

return text;
}

public static void main(String args) {
count = 0;
lock = false;
try {
AloMundoServidor obj = new AloMundoServidor();
AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
Registry registry = LocateRegistry.getRegistry();
registry.bind("AloMundo", stub);
System.out.println("Servidor pronto!");
} catch (Exception e) {
System.err.println("Capturando excecao no Servidor: " + e.toString());
e.printStackTrace();
}
}


AluMundoCliente.java:



import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

public class AloMundoCliente {
private AloMundoCliente() {}
public static void main(String args) {
String host = "54.244.xxx.xxx";
try {
Registry registry = LocateRegistry.getRegistry(host);
AloMundo stub = (AloMundo) registry.lookup("AloMundo");
String resposta = stub.digaAloMundo();
System.out.println("resposta: " + resposta);
} catch (Exception e) {
System.err.println("Capturando a exceção no Cliente: " + e.toString());
e.printStackTrace();
}
}
}


AloMundo.java



import java.rmi.Remote;
import java.rmi.RemoteException;

public interface AloMundo extends Remote {
String digaAloMundo() throws Exception;
}


I execute telnet 54.244.xxx.xxx 1099 and its listing.
I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
And no sucess!



Edit.:Solved



Launch cliente:



java -Djava.security.policy=server.policy AloMundoCliente


Modified ClienteCode in Registry with server IP:



Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");


Create server.policy:



grant{
permission java.security.AllPermission;
};


Launch server:



java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer









share|improve this question





























    0















    I have two machines:



    Server: AWS - EC2 - Ubuntu 18.04 Lts



    Client: Windows 10



    If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine



    Code:



    AloMundoServidor.java



    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;
    import java.rmi.server.UnicastRemoteObject;
    import java.io.*;

    public class AloMundoServidor implements AloMundo {
    private static int count, fila = 0;
    private static boolean lock;

    public AloMundoServidor() {}

    public String digaAloMundo() throws Exception {
    System.out.println("Chamada de aplicacao Cliente recebida! " + count);
    /*fila++;
    if(lock){
    try {
    wait();
    } catch (InterruptedException e) {
    Thread.currentThread().interrupt();
    //Log.error("Thread interrupted", e);
    }
    }
    lock = true;
    */
    File file = new File("test.txt");

    BufferedReader reader = new BufferedReader(new FileReader(file));

    String text = "", line;
    while ((line = reader.readLine()) != null) {
    text = text + "n" + line;
    }

    count++;
    Thread.sleep(5000);

    // fila--;
    // notify();
    // if(fila==0) {
    // lock = false;
    // }

    return text;
    }

    public static void main(String args) {
    count = 0;
    lock = false;
    try {
    AloMundoServidor obj = new AloMundoServidor();
    AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
    Registry registry = LocateRegistry.getRegistry();
    registry.bind("AloMundo", stub);
    System.out.println("Servidor pronto!");
    } catch (Exception e) {
    System.err.println("Capturando excecao no Servidor: " + e.toString());
    e.printStackTrace();
    }
    }


    AluMundoCliente.java:



    import java.rmi.registry.LocateRegistry;
    import java.rmi.registry.Registry;

    public class AloMundoCliente {
    private AloMundoCliente() {}
    public static void main(String args) {
    String host = "54.244.xxx.xxx";
    try {
    Registry registry = LocateRegistry.getRegistry(host);
    AloMundo stub = (AloMundo) registry.lookup("AloMundo");
    String resposta = stub.digaAloMundo();
    System.out.println("resposta: " + resposta);
    } catch (Exception e) {
    System.err.println("Capturando a exceção no Cliente: " + e.toString());
    e.printStackTrace();
    }
    }
    }


    AloMundo.java



    import java.rmi.Remote;
    import java.rmi.RemoteException;

    public interface AloMundo extends Remote {
    String digaAloMundo() throws Exception;
    }


    I execute telnet 54.244.xxx.xxx 1099 and its listing.
    I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
    And no sucess!



    Edit.:Solved



    Launch cliente:



    java -Djava.security.policy=server.policy AloMundoCliente


    Modified ClienteCode in Registry with server IP:



    Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");


    Create server.policy:



    grant{
    permission java.security.AllPermission;
    };


    Launch server:



    java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer









    share|improve this question



























      0












      0








      0


      0






      I have two machines:



      Server: AWS - EC2 - Ubuntu 18.04 Lts



      Client: Windows 10



      If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine



      Code:



      AloMundoServidor.java



      import java.rmi.registry.LocateRegistry;
      import java.rmi.registry.Registry;
      import java.rmi.server.UnicastRemoteObject;
      import java.io.*;

      public class AloMundoServidor implements AloMundo {
      private static int count, fila = 0;
      private static boolean lock;

      public AloMundoServidor() {}

      public String digaAloMundo() throws Exception {
      System.out.println("Chamada de aplicacao Cliente recebida! " + count);
      /*fila++;
      if(lock){
      try {
      wait();
      } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      //Log.error("Thread interrupted", e);
      }
      }
      lock = true;
      */
      File file = new File("test.txt");

      BufferedReader reader = new BufferedReader(new FileReader(file));

      String text = "", line;
      while ((line = reader.readLine()) != null) {
      text = text + "n" + line;
      }

      count++;
      Thread.sleep(5000);

      // fila--;
      // notify();
      // if(fila==0) {
      // lock = false;
      // }

      return text;
      }

      public static void main(String args) {
      count = 0;
      lock = false;
      try {
      AloMundoServidor obj = new AloMundoServidor();
      AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
      Registry registry = LocateRegistry.getRegistry();
      registry.bind("AloMundo", stub);
      System.out.println("Servidor pronto!");
      } catch (Exception e) {
      System.err.println("Capturando excecao no Servidor: " + e.toString());
      e.printStackTrace();
      }
      }


      AluMundoCliente.java:



      import java.rmi.registry.LocateRegistry;
      import java.rmi.registry.Registry;

      public class AloMundoCliente {
      private AloMundoCliente() {}
      public static void main(String args) {
      String host = "54.244.xxx.xxx";
      try {
      Registry registry = LocateRegistry.getRegistry(host);
      AloMundo stub = (AloMundo) registry.lookup("AloMundo");
      String resposta = stub.digaAloMundo();
      System.out.println("resposta: " + resposta);
      } catch (Exception e) {
      System.err.println("Capturando a exceção no Cliente: " + e.toString());
      e.printStackTrace();
      }
      }
      }


      AloMundo.java



      import java.rmi.Remote;
      import java.rmi.RemoteException;

      public interface AloMundo extends Remote {
      String digaAloMundo() throws Exception;
      }


      I execute telnet 54.244.xxx.xxx 1099 and its listing.
      I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
      And no sucess!



      Edit.:Solved



      Launch cliente:



      java -Djava.security.policy=server.policy AloMundoCliente


      Modified ClienteCode in Registry with server IP:



      Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");


      Create server.policy:



      grant{
      permission java.security.AllPermission;
      };


      Launch server:



      java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer









      share|improve this question
















      I have two machines:



      Server: AWS - EC2 - Ubuntu 18.04 Lts



      Client: Windows 10



      If I try run my code just in AWS machine it's work normally, but if i try same in other machine I have ConnectionRefused by time in Client machine



      Code:



      AloMundoServidor.java



      import java.rmi.registry.LocateRegistry;
      import java.rmi.registry.Registry;
      import java.rmi.server.UnicastRemoteObject;
      import java.io.*;

      public class AloMundoServidor implements AloMundo {
      private static int count, fila = 0;
      private static boolean lock;

      public AloMundoServidor() {}

      public String digaAloMundo() throws Exception {
      System.out.println("Chamada de aplicacao Cliente recebida! " + count);
      /*fila++;
      if(lock){
      try {
      wait();
      } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      //Log.error("Thread interrupted", e);
      }
      }
      lock = true;
      */
      File file = new File("test.txt");

      BufferedReader reader = new BufferedReader(new FileReader(file));

      String text = "", line;
      while ((line = reader.readLine()) != null) {
      text = text + "n" + line;
      }

      count++;
      Thread.sleep(5000);

      // fila--;
      // notify();
      // if(fila==0) {
      // lock = false;
      // }

      return text;
      }

      public static void main(String args) {
      count = 0;
      lock = false;
      try {
      AloMundoServidor obj = new AloMundoServidor();
      AloMundo stub = (AloMundo) UnicastRemoteObject.exportObject(obj, 0);
      Registry registry = LocateRegistry.getRegistry();
      registry.bind("AloMundo", stub);
      System.out.println("Servidor pronto!");
      } catch (Exception e) {
      System.err.println("Capturando excecao no Servidor: " + e.toString());
      e.printStackTrace();
      }
      }


      AluMundoCliente.java:



      import java.rmi.registry.LocateRegistry;
      import java.rmi.registry.Registry;

      public class AloMundoCliente {
      private AloMundoCliente() {}
      public static void main(String args) {
      String host = "54.244.xxx.xxx";
      try {
      Registry registry = LocateRegistry.getRegistry(host);
      AloMundo stub = (AloMundo) registry.lookup("AloMundo");
      String resposta = stub.digaAloMundo();
      System.out.println("resposta: " + resposta);
      } catch (Exception e) {
      System.err.println("Capturando a exceção no Cliente: " + e.toString());
      e.printStackTrace();
      }
      }
      }


      AloMundo.java



      import java.rmi.Remote;
      import java.rmi.RemoteException;

      public interface AloMundo extends Remote {
      String digaAloMundo() throws Exception;
      }


      I execute telnet 54.244.xxx.xxx 1099 and its listing.
      I tried java AloMundoServidor -Djava.rmi.server.hostname='54.244.xxx.xxx'
      And no sucess!



      Edit.:Solved



      Launch cliente:



      java -Djava.security.policy=server.policy AloMundoCliente


      Modified ClienteCode in Registry with server IP:



      Registry registry = LocateRegistry.getRegistry("xx.xx.xx.xx");


      Create server.policy:



      grant{
      permission java.security.AllPermission;
      };


      Launch server:



      java -Djava.security.policy=server.policy -Djava.rmi.server.hostname=XX.XX.XX.XX AloMundoServer






      java windows amazon-web-services amazon-ec2 rmi






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 '18 at 23:56







      Lucas Arkantos

















      asked Nov 17 '18 at 19:45









      Lucas ArkantosLucas Arkantos

      44




      44
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354914%2fjava-rmi-aws-two-machine%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53354914%2fjava-rmi-aws-two-machine%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()