*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Questions 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 Questions" Watch "RMI Questions" New topic
Author

RMI Questions

Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Good evening,
I've searched all the posts regarding RMI in this forum and in the Java Intermediate forum and have not found any that address my issues. Can someone please help me?

I'm using Eclipse SDK 3.1.0 to run a small RMI program (if I can get this to work, I can get back to working on my B&S project). If I don't manually start the RMI server via the command line, I get a ConnectionException even though LocateRegistry.createRegistry(1099) is being invoked inside the server code. I understood that by invoking createRegistry(), it would start the RMI server, is this correct?

If I run the RMI server before running the program I then get a NotBoundException invoking Naming.lookup(). I started the RMI server at the root level (E:\ drive). Do I need to start the RMI server in the directory where the stub and skeleton is or where the class files are? My stub and skeleton are in a folder together, a subdirectory where all my class and java files are.

Perhaps the NotBoundException is due to my lack of understanding of what exactly is the parameter for the Naming.lookup()? It's the directory to what, the skeleton directory?

While searching other RMI posts, one post brought on a question about where the stub and skeleton should reside. If I have a client and server jar file, shouldn't the stub reside in the client jar file and the skeleton in the server jar file?

Thanks for you time and feedback!
Alex Belisle Turcot
Ranch Hand

Joined: Apr 26, 2005
Posts: 516
Hi,

Yes LocateRegistry.createRegistry(1099) will start the "rmiregistry.exe".

After that, you need to bind the server object to it:


For this code to work, you must create the stubs for the ServerObject.

Then, on the client's side, you need to lookup for the "SomeText" to get the object:

Here, IP could be another machine's ip, or "localhost" if the client and server are on the same machine. It's where rmiregistry.exe is running, which is always on the same machine as the server (rmiregistry limitation: meaning a server cannot bind itself to a remote rmiregistry.exe).

The client needs to have access to the stubs too.

I believe in current java version, the skeleton is not used (managed behind the scene). not sure.

NotBOundException is thrown (on the client's side) because your server object was not previously bound successfully before you tried to lookup for it.

Hope this helps, any guru please feel free to correct me and help him some more.

Regards,
Alex
[ February 04, 2006: Message edited by: Alex Turcot ]
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
Shannon,

I use the LocateRegistry classes in my code and bypass Naming all together

Server:


Client:


Good luck,

Kevin
[ February 05, 2006: Message edited by: Kevin Conaway ]
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Hi Alex,
Thank you for your reply! This is a wonderful place where others are so kind to share their knowledge.

I guess a good nights rest is all I needed...the server side code needed to be executed before running the client code...I was only running the client code, which explains why I was getting a ConnectException.

Thanks Alex!
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Hi Kevin,
Thanks for your reply. Very interesting, most of the posts I've seen use the Naming instead of the Registry? It seems logical to use the Registry, however most of the posts are using the Naming, instead? It is more efficient to use the Registry?
Kevin Conaway
Ranch Hand

Joined: Jan 27, 2006
Posts: 57
Shannon,

I believe the Naming class is just a shortcut for the LocateRegistry methods. Most people use the Naming methods because most tutorials and guides use them. Naming apparently just parses the url that it accepts and passes it along to LocateRegistry.

I don't believe there is an inherent advantage to using either of these. For code consistency however, if you are using LocateRegistry, you should stick with that.

Kevin
Shannon Sims
Ranch Hand

Joined: Jul 03, 2003
Posts: 197
Hi Kevin,
Thanks for the explanation. Either way, I guess I'm safe to utilize the Naming or Registry APIs.
Bob Nedwor
hangman
Ranch Hand

Joined: Aug 17, 2005
Posts: 215

Kevin!
You Rock! This info has helped me tremendously!!! Thanks a bunch!

--Bob (the RMI wanna-be)


Bob N
SCJP - 1.4
SCJD - (B&S) Used 1.5 And It Runs On Solaris10
SCWCD - Thanks to HFSJ!!
Yupp Cook
Ranch Hand

Joined: Feb 07, 2006
Posts: 49
Even better it seems to me

using registry.rebind(...) instead of registry.bind(...)
avoid the AlreadyBoundException

Regards
Y


SCJP 1.4<br />SCJD (BS2.1.2)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RMI Questions
 
Similar Threads
how to get Clients CPU information on Server using Java RMI
Question regarding RMI
Package problem
Jar-Jar Binks and Stubs
rmi question