• Post Reply Bookmark Topic Watch Topic
  • New Topic

RMI remote objects

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been trying to understand how RMI works.
I have been playing around with a simple example.
I have:
1. A client application (HelloClient)
2. An interface (HelloInter)
3. A server implementation (HelloImpl)
4. A class that creates an object. (Person) This class is stored in a separate file from the server implementation.
I am trying to get the server to return the Person object to the client. The Person object consists only of two string constants:
public class Person implements java.io.Serializable{
String first = "Hello";
String last = "Hello everyone";
Person(){
}
}
In my client application I have these statements:
HelloInter h = (HelloInter)Naming.lookup("//134.253.212.176/hello");
Person p = h.getPerson();
The server implementation has:
public Person getPerson() throws RemoteException {
return new Person(); }
After the client receives the person object:
System.out.println("HelloClient says: " + p.first);
I have noticed that I have to have a copy of Person.class on the client side in order for the connection to work. However, I know that the object is being sent from the server.
I tried changing the constants in the Person object on the server side only. When the client application made the println call, the constant from the server was printed.
But, when I delete the Person.class file on the client side, the connection will not work.
Is there a way to do this without having the Person.class file on the client's computer?
Thanks for your help
Anne
 
Milind Kulkarni
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anne,
Can you send me your source code at milindkulkarni@usa.net?
Regards,
Milind
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my knowledge you must have the shared class files on both ends.
Originally posted by anne:
I have been trying to understand how RMI works.
I have been playing around with a simple example.
I have:
1. A client application (HelloClient)
2. An interface (HelloInter)
3. A server implementation (HelloImpl)
4. A class that creates an object. (Person) This class is stored in a separate file from the server implementation.
I am trying to get the server to return the Person object to the client. The Person object consists only of two string constants:
public class Person implements java.io.Serializable{
String first = "Hello";
String last = "Hello everyone";
Person(){
}
}
In my client application I have these statements:
HelloInter h = (HelloInter)Naming.lookup("//134.253.212.176/hello");
Person p = h.getPerson();
The server implementation has:
public Person getPerson() throws RemoteException {
return new Person(); }
After the client receives the person object:
System.out.println("HelloClient says: " + p.first);
I have noticed that I have to have a copy of Person.class on the client side in order for the connection to work. However, I know that the object is being sent from the server.
I tried changing the constants in the Person object on the server side only. When the client application made the println call, the constant from the server was printed.
But, when I delete the Person.class file on the client side, the connection will not work.
Is there a way to do this without having the Person.class file on the client's computer?
Thanks for your help
Anne

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!