Проблема с подключением к серверу RMI, работающему на сервере Amazon AWS EC2 - PullRequest
0 голосов
/ 04 октября 2018

Я новичок в использовании облака AWS, поэтому я пытаюсь развернуть простое echo rmi java в приложении amazon ec2. Я открыл все входящие / исходящие порты и запускаю его командой

java EchoRMIServer private_ip

используя putty ssh client.

основной сервер rmi:

public static void main(String[] args) {
    // Register the remote object with the RMI registry
    final int REGISTRYPORT = 1100;
    if(args.length!=1){
        System.out.println("EchoRMIServer <registryHost>");
    }
    String registryHost = args[0];
    String serviceName = "EchoService";
    try {
        String completeName = "rmi://" + registryHost + ":" + REGISTRYPORT + "/" + serviceName;
        EchoRMIServer serverRMI = new EchoRMIServer();
        System.out.println(completeName);
        Registry registry=  LocateRegistry.createRegistry(REGISTRYPORT);
        registry.bind(completeName, serverRMI);
        System.out.println("EchoRMIServer bound");
    }
    catch (Exception e) {
        System.err.println("EchoRMIServer exception: ");
        e.printStackTrace(); 
    }
}

, а клиент:

//Start the RMI client
public static void main(String[] args)  {

    final int REGISTRYPORT = 1100;
    String registryHost = null;
    String serviceName = "EchoService"; 
    BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
    // Check for hostname argument 
    try {
        if (args.length != 1) { 
            System.out.println("Usage: EchoRMIClient <hostname>");
            System.exit(1); 
        }   
        registryHost = args[0];

        // Construct a name to use to look up the remote object,
        // using the same name used by EchoRMIServer to bind its remote object to the RMI registry
        String completeName = "rmi://" + registryHost + ":" + REGISTRYPORT + "/" + serviceName;
        // Look up the remote object by name in the server host's registry
        System.out.println(completeName);
        Registry registry = LocateRegistry.getRegistry(registryHost,REGISTRYPORT);
        EchoInterface serverRMI = (EchoInterface) registry.lookup(completeName);


        //Interact with user
        String message, echo;
        System.out.print("Message? ");
        message = stdIn.readLine();
        //Call remote method
        echo = serverRMI.getEcho(message);
        System.out.println("Echo from remote method: "+echo+"\n");
    } // end try
    catch (Exception e) {
        System.err.println("EchoRMIClient exception: ");
        e.printStackTrace(); 
    }
} // end main

я запускаю клиент на своей машинес:

 java EchoRMIClient public_ec2_instance_ip

но я получаю ошибку:

 EchoRMIClient exception: 
 java.rmi.NotBoundException: rmi://X.X.X.X:1100/EchoService
at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:227)
...
...