The moose likes Distributed Java and the fly likes How does the port determined Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "How does the port determined " Watch "How does the port determined " New topic

How does the port determined

Kumar Kausikasa
Ranch Hand

Joined: Jun 04, 2002
Posts: 45
Hi ,
I understand how rmi works. The client requests an object by name to the RMI registry, once the client has the stub it make calls to the remotes method.I have gone through the RMI specification doc and underneath it actually opens a socket, but who determines on which port it shoud talk?..Is this done at compile time and run time?
Can someone explain in detail.
Thanks for your time
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Praveen,
Well I don't pretend to be an expert on RMI but I will tell you what little I do know about RMI and ports. The RMI registry is bound to port 1099 by default but can be bound to virtually any available port on the system. Now when a client requests a connection to a service that is bound to the RMI registry then the RMI server usually opens an anonymous port (which is whatever available port the system gives it) for that client to communicate with the remote service. It's like you creating a ServerSocket like:

This is why RMI has such a hard time with firewalls. Nobody knows for sure what ports are going to be needed. When this problem arises though custom SocketFactories can be implemented to use selected ports.
Hope this helps,
Michael Morris

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: How does the port determined
It's not a secret anymore!