i have this classes
//TableTalk.java -- a remote interface
package tabletalking;
import java.rmi.*;
public interface TableTalk extends Remote {
public String getTopic() throws RemoteException;
}
//TableTalkImpl.java -- a remote object
package tabletalking;
import java.rmi.*;
public class TableTalkImpl implements TableTalk {
private String[] questions = {"What is your favorite time of the
day?",
"What is your favorite fruit or
vegetable?",
"Talk about something beautiful you saw this week.",
"What I like best about our family
is ... ",
"Tell about a mistake you have made
recently.",
"Tell about a time when you felt happy.",
"How do you react when someone
crowds in line in front of you?",
"Talk about a special gift that you
remember.",
"If your family received a gift of
$5,000, how would you like your family to spend it?",
"Tell about a family tradition that
you enjoy."
};
private int idx = 0;
public String getTopic() throws RemoteException {
idx = (int)(Math.random()*questions.length);
return questions[idx];
}
}
//TableTalkSetup.java -- a set-up program
package tabletalking;
import java.rmi.*;
import java.rmi.activation.*;
import java.util.Properties;
public class TableTalkSetup {
public static void main(String[] args) throws Exception {
System.setSecurityManager(new RMISecurityManager());
Properties props = new Properties();
props.put("java.security.policy", "/myrmi/myrmi.policy");
ActivationGroupDesc.CommandEnvironment ace = null;
ActivationGroupDesc exampleGroup = new ActivationGroupDesc(props, ace);
ActivationGroupID agi =
ActivationGroup.getSystem().registerGroup(exampleGroup);
String location = "file:/myrmi/tabletalking/";
MarshalledObject data = null;
ActivationDesc desc = new ActivationDesc
(agi, "tabletalking.Migration", location, data);
TableTalk tt = (TableTalk)Activatable.register(desc);
System.out.println("Got the stub for the TableTalkImpl");
Naming.rebind("Topic", tt);
System.out.println("Exported a table-talking object");
System.exit(0);
}
}
//Migration.java -- migrate an existing remote object
package tabletalking;
import java.rmi.*;
import java.rmi.activation.*;
public class Migration implements TableTalk{
private TableTalkImpl tti = new TableTalkImpl();
public Migration(ActivationID id, MarshalledObject data) throws
RemoteException {
Activatable.exportObject(this,id, 0);
}
public String getTopic() throws RemoteException {//adaptee
return tti.getTopic();
}
}
//TableTalkClient.java -- test the remote object
package tabletalking;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class TableTalkClient {
private static TableTalk stub = null;
private TableTalkClient() {}
public static void main(String[] args) {
try {
Registry reg = LocateRegistry.getRegistry();
stub = (TableTalk) reg.lookup("Topic");
System.out.println("What is the topic for dinner table?
\n" + stub.getTopic());
} catch (Exception e) {
System.err.println("Client exception thrown: " + e.toString());
e.printStackTrace();
}
}
}
grant {
// Allow everything for now
permission java.security.AllPermission;
};
i compile and run this way.but in runnig a clien i encountered problem.
could any one help me plz,plz,plz.....
C:\myrmi>set classpath=
C:\myrmi>start rmiregistry
C:\myrmi>start rmid -J-Djava.security.policy=C:\myrmi\policy/
C:\myrmi>java -Djava.security.policy=C:\myrmi\policy/
tabletalking.TableTalkSetup
Got the stub for the TableTalkImpl
Exported a table-talking object
C:\myrmi>java -Djava.security.policy=C:\myrmi\policy/
tabletalking.TableTalkClient
Client exception thrown: java.rmi.UnmarshalException: Error
unmarshaling return
header; nested exception is:
java.io.EOFException
java.rmi.UnmarshalException: Error unmarshaling return header; nested
exception
is:
java.io.EOFException
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at sun.rmi.server.ActivatableRef.invoke(Unknown Source)
at
java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unkn
own Source)
at
java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at $Proxy0.getTopic(Unknown Source)
at tabletalking.TableTalkClient.main(TableTalkClient.java:17)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(Unknown Source)
... 7 more
C:\myrmi>