public interface MyRemote extends Remote {
public String sayHello() throws RemoteException;
}
public class MyRemoteClient {
public static void main(String[] args) {
new MyRemoteClient().go();
}
public void go() {
try {
MyRemote service = (MyRemote) Naming.lookup("rmi://129.168.10.107/RemoteHello");
String s = service.sayHello();
System.out.println(s);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class MyRemoteImpl extends UnicastRemoteObject implements MyRemote {
protected MyRemoteImpl() throws RemoteException {
super();
}
private static final long serialVersionUID = -1667780102301508304L;
@Override
public String sayHello() throws RemoteException {
return "From the server, 'Hello...'";
}
public static void main(String[] args) {
Remote service;
try {
service = new MyRemoteImpl();
Naming.rebind("RemoteHello", service);
} catch (Exception e) {
e.printStackTrace();
}
}
}