aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Registry help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Registry help" Watch "RMI Registry help" New topic
Author

RMI Registry help

Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi:
I am using RMI registry to register remote objects. In the registery, I have the line:

LocateRegistry.createRegistry(1099);
Naming.rebind(serverName, data);

Sometime it work fine, and sometimes it give me this error:
java.net.BindException: Address already in use: JVM_Bind

can someone explain to me what is going on?
thanks


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Denis Spirin
Ranch Hand

Joined: Mar 22, 2004
Posts: 72
http://www.jguru.com/faq/view.jsp?EID=126267

http://swforum.sun.com/jive/thread.jspa?threadID=44757

http://www.pramati.com/DevPortalWeb/forum/thread.jsp?forum=61&thread=2266&metainfo=Server%20not%20starting.%20Java.net.BindException


Regards<br /> <br />Ph.D.<br />SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD 2
Jon Entwistle
Ranch Hand

Joined: Feb 20, 2003
Posts: 118
Hi Hanna,

The reason for your error is rooted in the fact that TCP/IP 'guarantees' delivery of data. As part of this, each connection between sokects on two computers (or one computer with the loopback) must be unique.

Think of it as though a computer is like a telephone exchange with a unique address (its IP address) and up to 65,535 telephone numbers (the total number of ports in a computer). When a server program starts on a computer (or more accurately an IP address), it reserves one of the ports for its exclusive use. This is like somebody reserving exclusive use of one of the telephone numbers in the telephone exchange. For SSH for instance, this is port is 22. The default port for RMI is 1099 if I remember. The combination of an IP address and a port number is known as a socket.

This 'reserving' of a port is known as binding. Once a port has been bound by a service, another program cannot bind itself to this same port. This makes sense as if, say, two ftp servers are trying to listen on the same port - which would answer a connection request from a client?

So what is a connection? It is a socket pair made up of the client IP address and port number along with the server IP address and port number. This must be unique for the reasons I have just explained.

The error message you have is because you are trying to bind a port number which has already been bound by another program. This will be because you have started the RMI server once, binding it to port 1099. You have then attempted to start another instance of the server on the same port. You will not be allowed to do this for the reasons above. You will need to stop the first instance of the server to release/unbind this port first.

Regards,

Jon
[ June 05, 2004: Message edited by: Jon Entwistle ]

SCJD, SCEA
Sean Gildea
Ranch Hand

Joined: Jul 01, 2004
Posts: 81
I'm getting the same error when i try a port other than 1099, and I checked Netstat to make sure I wasnt using a port already in use

anyone have any ideas?


SCJD, SCBCD, SCJP
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11424
    
  85

Hi Sean,

I'm getting the same error when i try a port other than 1099, and I checked Netstat to make sure I wasnt using a port already in use

anyone have any ideas?


The common problem that people come across when their RMI Registry uses a non default port is that they forget to use the non default port when binding their server application.

I would recommend you post your relevant lines of code (like Hanna did), and post the exception you get.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Sean Gildea
Ranch Hand

Joined: Jul 01, 2004
Posts: 81
Thanks Andrew!

Here is the code that works when I input 1099 in my port connection box, but that errors out ( exception below ) when I put in a different port number.



Here is the exception I get

Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11424
    
  85

Hi Sean,

Here is the code that works when I input 1099 in my port connection box, but that errors out ( exception below ) when I put in a different port number.




The problem here is that the call to Naming.rebind is going to use the standard port of 1099, which doesnt exist if you started a registry on a different port.

The LocateRegistry.createRegistry() method returns the registry just created. So you can then use the rebind() method of that particular registry, which will ensure you are using the correct port.

Regards, Andrew
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RMI Registry help