This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Distributed Java and the fly likes RMI question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI question" Watch "RMI question" New topic
Author

RMI question

Frans Verbeke
Greenhorn

Joined: Mar 30, 2009
Posts: 11
Can I setup an RMI registry on a random port (by giving 0 as port parameter) and then find out wich port was chosen ?

If so, how ?
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

No. Choose a port such as:
The port numbers are divided into three ranges: the Well Known Ports,
the Registered Ports, and the Dynamic and/or Private Ports.

The Well Known Ports are those from 0 through 1023.
The Registered Ports are those from 1024 through 49151
The Dynamic and/or Private Ports are those from 49152 through 65535


Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
Frans Verbeke
Greenhorn

Joined: Mar 30, 2009
Posts: 11
Thanks for your reply.

The problem is I can't say in advance if a port will be free or not.

So... a solution for me would be to choose a range of ports. For example: 2000 - 2100.
And then start by trying one...if it doesn't work, try another one...and so on, till I find one that works.

Will I get a recoverable(by trying another port) exception when a port isn't free ?
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

1099 is a port registered to be the RMI Registry port.

What you're doing is outside anything I know about. Perhaps other will step in here.
Frans Verbeke
Greenhorn

Joined: Mar 30, 2009
Posts: 11
Yes, it seems 1099 is the standard port for this. Nevertheless I was hoping to be able to choose another port.

In the API docs I found this:



Which makes me think it's possible to choose another port.

Except the RemoteException I don't see any other exceptions listed, so I was wondering if it would be possible to try ports till I find one that's free.

I could be totally wrong here; it's not like I have experience with RMI.

Any input is always appreciated.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
When you manually start the RMI server (registry) you select the port that you want it to use.

Before you manually start the RMI server (registry) you should know what port you will use.

Your concept of "trying" ports until one is free does not apply to the activity of manually starting the RMI server (registry.)
Frans Verbeke
Greenhorn

Joined: Mar 30, 2009
Posts: 11
Jimmy Clark wrote:
When you manually start the RMI server (registry) you select the port that you want it to use.
Your concept of "trying" ports until one is free does not apply to the activity of manually starting the RMI server (registry.)


Ok, I guess I'll just have to try it. If necessary I can allways check if a port is free by doing something like the following.



The only problem with this could be something takes the port between me checking if it's free and actually using it with the registry, but the chance on that is small enough.

Maybe you're wondering how I will be able to use this registry if I don't know beforehand what port I'll use...I will probably be sending out udp packets to tell clients what port to use.

Thank you for thinking with me here and sorry for using your time.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RMI question