1. 定義遠程接口
// 遠程接口繼續自Remote
// 遠程方法的傳入參數和返回值必須是自然類型(int,float,boolean等)
// 或者實現了Serializable或Remote接口的對象。
public interface Time extends java.rmi.Remote {
// 遠程方法必須拋出RemoteException:
public String getTime() throws RemoteException;
}
2. 定義實現類
// 注重:實現類繼續自UnicastRemoteObject和自定義的遠程接口Time:
public class TimeImpl extends java.rmi.server.UnicastRemoteObject implements Time {
// 注重:由于RemoteObject構造函數要拋出RemoteException,
// 因此務必定義構造函數并拋出RemoteException:
public TimeImpl() throws RemoteException { super(); }
// 這里是遠程方法:
public String getTime() throws RemoteException {
新聞熱點
疑難解答