Hi, I am building the basic functionality for client-server communication using RMI. When I try to lookup the RemoteData object (present in "suncertify.server" package) from a client (present in "client" package), I get the following error: RemoteConnection exception: suncertify.server.RemoteData_Stub java.lang.ClassCastException: suncertify.server.RemoteData_Stub at client.RemoteConnection.getConnection(RemoteConnection.java:11) at client.clientTest.main(clientTest.java:258) Remote Implementation available. Exception in thread "main" java.lang.NullPointerException at client.clientTest.<init>(clientTest.java:63) at client.clientTest.main(clientTest.java:259) But, when I copy the client class to the "suncertify.server" and access the RemoteData object, the application is running. Where am I making a mistake?! I also tried copying the RemoteData_Stub to the "client" folder, but still the above error was thrown. (RemoteData is the class which extends extends UnicastRemoteObject and implements DBMain (which extends Remote). RemoteData's main method binds the RemoteData object with the rmi-registry. The client lookups this object using rmi://ipaddress/obj) Dayanand.
Hi Dayanand, It looks to me like your trying to cast to the object instead of the interface. You can only cast to a Remote interface on the client thru RMI. That's why it works on the server when not using RMI. Hope this helps, Michael Morris
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Are you making use of codebase parameter and policy file? Try to run your app without them. Eugene.
Hi Eugene, I ran the client without specifying the codebase and policy file. The following is my directory structure: workspace -> Project ---> client ---> suncertify -------> data -------> server I have given "Full Permission" to the directory "workspace", using policytool. Dayanand.
Originally posted by Michael Morris: Hi Dayanand, It looks to me like your trying to cast to the object instead of the interface. You can only cast to a Remote interface on the client thru RMI. That's why it works on the server when not using RMI. Hope this helps, Michael Morris
Hi Michael, The following are what I use in the "client": ConnectionFactory (an interface) LocalConnection implements ConnectionFactory RemoteConnection implements ConnectionFactory When the client is started with "alone" (or) no parameters, the LocalData object is returned by LocalConnection. When the client is started with "server" as parameter, I connect to RMI Registry to get the RemoteData object. For both, I do the following in client: DBMain obj = (DBMain) LocalData.getConnection(); (or) DBMain obj = (DBMain) RemoteData.getConnection(); DBMain is an interface. LocalData and RemoteData implements this interface. I am not sure if this is done properly. The following is what I have done: I have DBMain interface in the "client" package as well as in the "suncertify.server" package. The only difference between these files is that the DBMain interface in the "suncertify.server" package "extends Remote" and all methods "throws RemoteException". The RemoteData (in suncertify.server package) implements the DBMain interface (in the suncertify.server package). When I get the RemoteData object I cast it to DBMain interface (as shown above - in the client package). Should I copy the DBMain interface used in the "suncertify.server" package in "client" package? Dayanand.