This discussion is archived
0 Replies Latest reply: Jan 17, 2007 2:06 PM by 807596 RSS

RMI Help

807596 Newbie
Currently Being Moderated
I am running into a bit of a problem with RMI. It took me a long time to come to the conclusion that I have come to. I know I must be wrong, but all of my tests confirm this. Here is the setup: the simplest RMI test possible.
import java.rmi.Remote;
import java.rmi.RemoteException;


public interface TestInt extends Remote {
     
     public void foo() throws RemoteException;
}

------- next file ------

import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javax.swing.JFrame;


public class Host implements TestInt, Serializable {
     private static Registry r;
     
     public static void main(String[] args) throws Exception {
          r = LocateRegistry.createRegistry(1099);
          r.bind("T", new Host());
          
          new JFrame("foo").setVisible(true); //just to keep the server running
     }

     public void foo() throws RemoteException {
          System.out.println("RMI method is executing on this machine");
     }
}

------- next file -------

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


public class Client {
     
     
     public static void main(String[] args) throws Exception {
          Registry r = LocateRegistry.getRegistry("192.168.0.5", 1099); //connect to 192.168.0.5
          TestInt t = (TestInt) r.lookup("T");
          
          System.out.println(t.getClass().getName());
          t.foo();
     }
}
The JFrame in the Host file is just to keep the server running. When I execute this, the host computer doesn't show the output, but the client computer does. Not only that, but the class name of the 'stub' that I should be getting in the client is 'Host'. Here is the printout of the client

Host
RMI method is executing on this machine

This leads me to the conclusion that the host sends the serialized version of the class to the client, then the client executes the methods on the client side. This doesn't make any sense at all. Please help