Is there a way to control the ports opened by an RMI server while accepting connections from a client. I see that I can control the port that an RMI server listens on while exporting the server object using UnicastRemoteObject.exportObject. However, when the client connects to the server, I see different ports being used between the server and the client when the server accepts a connection from the client.

srinath mandalapu

I don't think you can control the value of the port returned by the accept call on server side runtime. This port is determined by the OS at runtime depending upon the availbility of the port. Atleaset on the client side, you can bind the socket to a particular local port before making a connection to the remote server in normal socket programming. But in RMI, RMI reference layer manages connection management.