This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Distributed Java and the fly likes Urgent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "Urgent" Watch "Urgent" New topic
Author

Urgent

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
This is what I am trying to do and not able to get a solution.
public interface X extends Remote {
public void methodOne() throws RemoteException;
public Z methodTwo() throws RemoteException; //Z is a class
}
public class XImpl implements X {
public void methodOne() throws RemoteException {
// body
}
public Z methodTwo() throws RemoteException {
//body
return new Z();
}
}
public class MyServer {
public MyServer(){
X x=(X)new XImpl();
UnicastRemoteObject.exportObject(x);
Naming.rebind("rmi://localhost:1099/MyServer", x);
}
public static void main(String s[]) {
new MyServer();
}
}
Now when I call the methodOne from the client, it works fine but if I try to call methodTwo, the return type is null.
I tried creating an interface for Z(say ZInter) and made Z implement the interface ZInter and created the stub and the skeleton classes. But now, I do not know how do I refer them in the client.
Please reply ASAP.
Milind Kulkarni
Ranch Hand

Joined: Jun 01, 2000
Posts: 146
Hi Smita,
Can you specify the details of Z class.
Regards,
Milind
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Z class is just another class that has a few data members, a few methods and the class implements Serializable.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Milind, I am still waiting for reply.
Please answer the query ASAP.
Smita.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Smita
According my view u should copy the class Z on to the client's
machine .Bcoz that return type will not be understood by jvm
which is not a standard class .
u can reach me at vish_venu9@hotmail.com
regards
venu
Milind Kulkarni
Ranch Hand

Joined: Jun 01, 2000
Posts: 146
Hi Smita,
There is absolutely no difference in the way you call remote method (on the different host) and the local method ( on the same host). As pointed out by Venu make sure that your client can access Z class implementation either copying class Z in your client directory or dynamically loading class using CODEBASE.
Regards,
Milind
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Milind, Can you show it with the help of some sample code. It would be really helpful.
Thanks,
Smita.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The Object you are passing must implement java.io.serializable. Once that is done it can be used as if it were local objects.
I coded and run a program very similar to the one you were trying to develop. It works fine.
If you want the source code please mail me at moh@srasys.co.in
or mohan@the-pentagon.com
 
Don't get me started about those stupid light bulbs.
 
subject: Urgent