How Can I Use Class LocateRegistry To Manually Start RMI Registry?

1

1 Answers

Virgo Nadia Profile
Virgo Nadia answered
In RMI you can have references to "remote objects". These are objects that are on another computer but you interact with them as if they were local. The entity you get for an object remotely is actually not the object itself, but an interface that objects implements. The interface must extend java.rmi.Remote.An object can register itself with the RMI registry using the rebind method of java.rmi.Naming. (You have to start a local registry with rmiregistry first.) Objects can get a remote reference to a registered object using the lookup method of java.rmi.Naming.Now we get to try to write something fun using RMI. I give you the example to use class LocateRegistry to manually start RMI registry.
Assume the port number is 2007, you may code as follows:
//in your server program
LocateRegistry.createRegistry (2007);
Registry registry = LocateRegistry.getRegistry (2007);
//in your client program
Registry registry = LocateRegistry.getRegistry (2007);
//If the RMI server is located somewhere, use:
Registry registry = LocateRegistry.getRegistry (hostName, 2007);

Answer Question

Anonymous