Search code examples
portrmi

How to get the port number of client in rmi?


In RMI the server opens the registry on some port and then the clients connects to the server. Is there any way knowing on which port the connection is made between the server and the client? I know the default port for RMI is 1099 but what is the port number on the client side? Does the client even opens a port?


Solution

  • The client does have a local port, as in any TCP connection, but there is no way for the server to discover it short of a custom socket factory.

    There's also no reason for the server to need it. It's not a useful piece of information. It's not a listening port, so you can't connect to it; it changes from time to time; and it doesn't uniquely identify the client, because of client-side connection pooling and server-side idle connection timeouts.