File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes port field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "port field" Watch "port field" New topic

port field

steve nicholls

Joined: Dec 10, 2002
Posts: 20
I am not using the port number parameter, we can request from the user. When I start the server, I use Naming.rebind("serverName", Object) and when the client connects to the server, it uses:
Where ipAddress is the IP address without a port number. So is the port field necessary? Does the RMI client seek out the first available RMI server at that IP address with that name? Can errors occur if the port number is not specified?
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

I didn't include port number. The RMIRegistry by default starts on port 1099. I took the default and used that.

Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
steve nicholls

Joined: Dec 10, 2002
Posts: 20
Thanks Mark.
FYI: I did a little research into this area. As you stated, the RMI server will default to port 1099 if the default UnicastRemoteObject constructor is used. Likewise, serveral RMI servers can be loaded onto one port, with the server name being the unique identifier. Consequently, when using rebind(String, Object) to specify the server name (String), the method will fail if the name already exists. If no port is specified on the client side (in the rmi url), the lookup(String) method will search on port on the default port. So it would appear for this program, a port does not need to be specified, but the server should ensure the Server name is unique before trying to rebind.
Also, as a side note, the default RMI port can be switched by specifying this in the command line, for example:
$ rmiregistry 10123
will use port 10123 as the default port. I hope this research is useful to anyone else with port questions.
I agree. Here's the link:
subject: port field
It's not a secret anymore!