This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes rmiregistry and server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "rmiregistry and server" Watch "rmiregistry and server" New topic

rmiregistry and server

Zhaozhe Ruan

Joined: Mar 06, 2006
Posts: 17
could anyone tell me if i can start the server without run rmiregistry first?

i wanna start the server with "localhost" "port"
but if I rum "rmiregistry 1024", i could only assign the "port" 1024, or I can not start the server
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Use LocateRegistry.createRegistry(int port) method.

For instance, this codes creates a new RMIRegistry, and registers a Server object with it:

To shut down the RMI registry, I unexport the registry object.

I hope this helps!
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

You can export multiple remote objects in the same port.


Zhaozhe Ruan

Joined: Mar 06, 2006
Posts: 17
I've tried your way, but when I try to connect from client to server, connection was refused, could you give me some suggestions?

Daniel Bryant
Ranch Hand

Joined: Jul 15, 2006
Posts: 54
Hi Zhaozhe,

In answer to your original question, if I understand correctly, what you want to do is start the RMI registry using a user-defined port number?

If this is the case I would recommend displaying a GUI to the user (created and displayed by an object i.e. with a main method that is not the server and does not require RMI to be running) and then ask for the appropriate information (url, port), and only then do you need to start the registry and instantiate your server object using the GUI object.

Best wishes,


SCJP 1.4,<br />SCJD (URLyBird 1.2.1, JDK 5.0)
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
Zhaozhe, comrade.

The answer to your last question is fairly evident. If you create the RMIRegistry and bind your objects and you simply let your program finish then your server dies.

You have to make sure your application will not die until you want so.
For instance (this is just for an example), put at the end of your server initilization code, so that your server dies until you press enter.

Evidently you will have to provide some way to the end user to shut down the server when he wants.

This will require a shutdown strategy in order that any pendant transaction is completed before the server dies, and no further transactions should be accepted while the server is shutting down.

I hope this helps!
I agree. Here's the link:
subject: rmiregistry and server
Similar Threads
How wo stop and kill rmiregistry ?
start the server
classpah in readme
Singleton Pattern
Simple RMI Question ...