mercredi 6 mai 2015

RMI java, how to "remotely"

I just "created" a Client-Server Java RMI on the same java virtual machine(it's a trivial thing an RMI on the same machine). I want to use a Client-Server RMI remotely. I'll use two machines: the first, called A, will be the Server; the second, called B, will be the client. So I want to know which are the differents beewten remotely and locally RMI Client-Server. For example, on machine A:

  1. I write the code for the RemoteInterface extends Remote;
  2. I write the code for the class of real remote object:

    public class RemoteObj extends UnicastRemoteObject implements RemoteInterface
    
    
  3. I write the code for the server side which I bind the remoteObj using the IP of the machine A on the neetwork

    public class Server {
    ............
    RemoteObj obj = new RemoteObj();
    String globalName = "rmi//IP_machine_A/hello";
    Naming.rebind(globalName, obj);
    
    
  4. I use the rmic RemoteObj command to auto generate the stub

  5. I use the start rmiregistry command to start RMI registry server
  6. Finally I must start the server

On the machine B, instead:

  1. I write the code for Client, which I lookup the rmi registry with the global name:

     public class Client {
     .......
     String globalName = "rmi//IP_machine_A/hello";
     RemoteInterface remoteObj = (RemoteInterface)Naming.lookup(globalName);
    
    
  2. I must start the client

Are these statementes correct? Thanks guy

Aucun commentaire:

Enregistrer un commentaire