• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Problems with Java RMI

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
    Posts: 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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
     
    This. Exactly this. This is what my therapist has been talking about. And now with a tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic