8 Replies Latest reply: Jun 4, 2012 7:06 PM by EJP RSS

    RMI,can't get connect two computers.

    941219
      I'm noob in RMI and the material on the Internet is kind of hard to understand because the examples are all on the same computer which is odd, since the main purpose of the RMI is another. I tried to implement the server in a computer, and the client on another computer and follow the codes as below:

      What is wrong ?

      Computer 1 ->Server:
      [Java] package remoto; import java.rmi.Remote; import java.rmi.RemoteException; pu - Pastebin.com

      Computer 2-> Client:
      [Java] /*Same interface i have in my server computer.*/ package remoto; import java.r - Pastebin.com

      Thanks.
        • 1. Re: RMI,can't get connect two computers.
          EJP
          What is wrong with what? Please don't ask content-free or meaningless questions here. If you have a concrete problem, state it.
          • 2. Re: RMI,can't get connect two computers.
            941219
            Oh i'm sorry man, i did not see that the pastebin links are broken!
            The problem is i can't get connect two computers.

            I put this one on the server computer; pastebin/q5p1PPgp

            And this one on client computer; pastebin/uH3pqBqv
            • 3. Re: RMI,can't get connect two computers.
              EJP
              Nobody here should be expected to chase links, especially ones that don't work. Post your problem here or the thread will be locked.
              • 4. Re: RMI,can't get connect two computers.
                941219
                Alright man, i'm sorry once again, i already solved my problem.
                • 5. Re: RMI,can't get connect two computers.
                  941219
                  Hi again.
                  I'm compelled to post again about this problem, i thought that i had solved this, but no.
                  So i'm trying to connect two computer using RMI and this message error appears. I'll my my source code here to.
                  Can you help me to solve this problem?
                  Error message:
                  RemoteException: java.rmi.ConnectException: Connection refused to host: 127.0.1.1; nested exception is:
                  java.net.ConnectException: Connection refused 
                  In my server computer i have:
                    
                  import java.rmi.Remote;  
                  import java.rmi.RemoteException;  
                    
                  public interface Inter_Mensageiro extends Remote {  
                    
                      void enviarMensagem(String msg) throws RemoteException;  
                    
                      String lerMensagem() throws RemoteException;  
                    
                  }  
                  *********************************************************************************  
                  import java.rmi.RemoteException;  
                  import java.rmi.server.UnicastRemoteObject;  
                    
                  public class Impl_Mensageiro extends UnicastRemoteObject implements Inter_Mensageiro {  
                    
                      public Impl_Mensageiro() throws RemoteException {  
                          super();  
                      }  
                    
                      @Override  
                      public void enviarMensagem(String msg) throws RemoteException {  
                          System.out.println(msg);  
                      }  
                    
                      @Override  
                      public String lerMensagem() throws RemoteException {  
                          return "Ola mundo meu ovo!";  
                      }  
                    
                  }  
                  *********************************************************************************  
                  import java.rmi.Naming;  
                  import java.rmi.registry.LocateRegistry;  
                    
                  public class MensageiroServer {  
                      public static void main(String[] args) {  
                          try {  
                              Impl_Mensageiro m = new Impl_Mensageiro();  
                              LocateRegistry.createRegistry(1099);  
                              Naming.bind("//192.168.1.100/MensageiroService", m);  
                              System.out.println("Server working.");  
                          } catch (Exception e) {  
                              System.out.println("Erro no servidor: " + e);  
                          }  
                      }  
                  }  
                  *********************************************************************************  
                  In my client computer i have this code:
                  *********************************************************************************  
                  //Same interface that i have in my server computer.  
                  *********************************************************************************  
                  //Same class that implements interface that i have in my server computer  
                  *********************************************************************************  
                  import java.rmi.RemoteException;  
                  import java.rmi.Naming;
                  
                  public class MensageiroCliente {
                  
                      public static void main(String[] args) {
                          try {
                              Inter_Mensageiro m = (Inter_Mensageiro) Naming.lookup("//192.168.1.100/MensageiroService");
                              String resposta = m.lerMensagem();
                              System.out.println("Resposta do Server: " + resposta);
                          } catch (RemoteException e) {
                              System.out.println();
                              System.out.println("RemoteException: " + e.toString());
                          } catch (Exception e) {
                              System.out.println();
                              System.out.println("Exception: " + e.toString());
                          }
                      }
                  }
                  *********************************************************************************
                  • 6. Re: RMI,can't get connect two computers.
                    EJP
                    See item A.1 of the RMI FAQ on the RMI Home Page.
                    • 7. Re: RMI,can't get connect two computers.
                      941219
                      I type this code in server computer's terminal:
                      $ java -Djava.rmi.server.hostname=192.168.1.100 MensageiroServer
                      And this exception shows up:
                      Erro no servidor: java.rmi.ConnectIOException: Exception creating connection to: 192.168.1.100; nested exception is:
                      java.net.NoRouteToHostException: No route to host
                      • 8. Re: RMI,can't get connect two computers.
                        EJP
                        Can you ping that host from the client?