rajshkhr,
Both the client and the server need to know the RMI port they are running on ahead of time. Otherwise, the server wouldn't be able to send a message to the client telling it what port to listen to since the client wouldn't know what port to listen for the message on. Port 1099 shouldn't usually be in use by anything else since it is typically reserved for RMI. If it is also happening with other "random" ports, maybe the registry isn't being shutdown properly. Are you sure the registry is no longer running when you try to restart it? Also, is it possible that you are also trying to create it from your
java process using LocateRegistry.createRegistry and also start the rmiregistry process (effectively trying to start the registry twice)?
When you do get the error, you could use netstat to determine what is using that port.
Jeff