It some times throws an error that port is already bind.
I have also tried the default port for registry i.e. 1099 but some time same error occurs.
I think this might be because when I close my RMI registry some process might allocate the port on which my RMI registry was running and when I retry to run registry it gives me error.
Due to this I need to change the code in my client side where I have used Naming.loookup() method.
Also I have tried regisry.lookup() method but do not get any success.
If there is any method to run registry on random port and send it to client when client wants to connect to the server???
Or suggest me what to do.
Thanks in advance.
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.
Joined: Oct 14, 2009
Thanks for your reply.
Actually when ever I want to restart my registry I use to kill process method from the command prompt ensuring that RMI registry is shut down, and then restart registry with the same port number, then some time it throws an exception/error that port is already bind or some time it successfully starts on the same port.
Also some time on port no 1099 same exception is thrown.
Joined: Apr 07, 2007
I wonder if the hard kill is causing the port to stay active and not always shutting down properly. When it happens again, just run netstat to see what's using the port.