Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Distributed Java and the fly likes Problems with Java RMI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Problems with Java RMI" Watch "Problems with Java RMI" New topic
Author

Problems with Java RMI

Micheal Kim
Greenhorn

Joined: Jul 08, 2011
Posts: 2
Hi everyone,

I am new to Java RMI and I am simply trying to run a "Hello World" program which was slightly modified. (code is shown at the end of the message)

Basically, I have a remote class, a remote interface, and a server class in one of my computers and a client class in another computer.
I am trying to get a "hello" message from the server using the client.
I compiled the server/remote class/interface using javac and then using the rmic compiler. I can run the server and the stub with no problem.
When I try to run the client, I received errors:


cannot find symbol
symbol : class HelloInterface
location: class Client
HelloInterface hello = (HelloInterface)Naming.lookup(host);

I am wondering what would the problem be and how could I get this to work.
In addition, I believe I am using a stream TCP connection. How could I use a datagram UDP instead?

Thanks in advance!
Michael

Remote Interface:


Remote class:


Client:


Server:
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 489
    
    5
Which JavaSE version are you on? From the code and description (rmic, use of java.rmi.Naming), it looks like you're using a J2SE 1.3 example. But RMI concepts have changed a bit (evolved?) since then. I'll explain both how to get your existing version to work, as well as how to migrate to the newer concepts.

Getting your existing system to work: Checklist
  • Have you packaged your remote interface into a separate jar? This jar - the interface jar - containing remote interface definition and any types it uses, should be in the classpaths for rmiregistry, server and client.
  • Are the stub classes available in classpath for rmiregistry?
  • Are you running rmiregistry? (since you say server and stub are running ok, you must be running rmiregistry correctly, but just checking...)
  • Are you starting the components in this order: First: rmiregistry Second:server Last: client?


  • Migrating to JavaSE1.5 RMI concepts:
    The lookup and stub concept are changed as follows :
  • The java.rmi.Naming was a custom naming scheme specifically for RMI. Now, >JavaSE 5, it's preferred to use the standard JNDI concept like this:


  • server:


    client:


  • Prior to JavaSE 5, RMI involved stub classes generated using rmic on the server class. Since JavaSE 5, these are not needed because stubs are generated dynamically (using the dynamic proxy concept java.lang.reflect.Proxy) at runtime. So you can skip the rmic step completely.


  • Regarding UDP:
    When I saw UDP, I went ! RMI does allow the use of custom socket factory, but the custom sockets have to be TCP sockets (ie, subtypes of java.net.Socket, like SSLSocket). If you want to use UDP for RPC, you can - but not using any of the RMI infrastructure or APIs. Or you'd have to perform some contortions like using a TCP over UDP implementation. Why do you wish to use UDP for RPC?
    Micheal Kim
    Greenhorn

    Joined: Jul 08, 2011
    Posts: 2
    Thank you for your reply, Karthik Shiraly

    You were right, I actually just had to skip the rmic step and everything worked wonderfully!

    Regarding the UDP, I was a little bit confused about how RMI is implemented and I was wondering if there was an easy and simple way of changing from TCP to UDP.
    I see now that it is not how things work, but thanks for clarifying this to me!

    I really appreciate your help.
    Thanks again,
    Micheal
     
    wood burning stoves
     
    subject: Problems with Java RMI
     
    Similar Threads
    RMI Problem : java.lang.ClassCastException
    How to read Clients CPU information on Server
    RMI in netbeans on windows
    Remote Method Invocation Problem
    exception in client side