aspose file tools*
The moose likes Distributed Java and the fly likes Running RMI registry on ramdon port Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Running RMI registry on ramdon port" Watch "Running RMI registry on ramdon port" New topic
Author

Running RMI registry on ramdon port

rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
Hello all,

I am running my RMI registry in linux as

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.
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
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


Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
rajshkhr pandey
Ranch Hand

Joined: Oct 14, 2009
Posts: 35
Hello Jeff,

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.
Jeff Storey
Ranch Hand

Joined: Apr 07, 2007
Posts: 230
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running RMI registry on ramdon port