Java RMI AWS two machine











up vote
0
down vote

favorite












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









New contributor




Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
























    up vote
    0
    down vote

    favorite












    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









    New contributor




    Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      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









      New contributor




      Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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









      New contributor




      Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 17 at 23:56





















      New contributor




      Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 17 at 19:45









      Lucas Arkantos

      43




      43




      New contributor




      Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      Lucas Arkantos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





























          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',
          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
          });


          }
          });






          Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.










           

          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






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.













          Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.












          Lucas Arkantos is a new contributor. Be nice, and check out our Code of Conduct.















           


          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







          Popular posts from this blog

          Create new schema in PostgreSQL using DBeaver

          Deepest pit of an array with Javascript: test on Codility

          Costa Masnaga