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?
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:
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?
Joined: Jul 08, 2011
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.