Hi Marcos,
Throughout these discussions, everyone is always talking about the port the RMI Registry is listening on.
As programmers using RMI, we never know (or care) what port the server we write will be listening on, nor do we know (or care) which port the client will use to connect to the server.
During the
bind process, a port numbr gets assigned to our server. I do not know whether the server gets this port number, or whether it is assigned by the registry. I think the second option is more logical, but I just dont know (and dont really care

). This number is dynamic (that is, it can (and probably will) change each time you run your server).
So if I run my server (which starts my RMI Registry) I can see that I am now using two ports:
I can see here that port 1099 is bound (this is the RMI Registry) and port 33528 is bound (this is the dynamically allocated port number my server is listening on).
If I kill off the server process, and then restart it, I will get a different port number:
This time I got port number 33535 for my server.
The point is, that neither the code I write for my server, nor the code I write for my client ever needs to know this dynamic port number.
What happens is that when the server starts up, it gets allocated this changeable port number. The
registry knows that the server is using that particular port number, so that is all that matters.
When the client does a lookup for the services my server is offering, the RMI Registry will tell it that the services are being offered by a server which is on "machine
x, listening on port
y".
As long as the client knows how to get in touch with the RMI Registry, it can always find out what port the server is listening on.
And this answers your question
My problem is related to the use of port numbers at the client side. More specifically the port used as parameter in the client. I cant see what this parameter is good for. The client uses the port number in it's lookup command to connect to the RMI Registry. The RMI Registry does not have to be on port 1099, it could be on any port. So the client specifies what port it expects to find the RMI Registry on.
Once it has connected to the RMI Registry, it can find out what port the server is on.
The server never needs to know this.
The client does not care what outgoing port number it is using to connect to the server. This is handled automatically.
The server does not care what port number the client used to connect. All the server cares about is that it has a connection.
Is this making sense?
Regards, Andrew
[ May 16, 2003: Message edited by: Andrew Monkhouse ]