- 1. 定义一个接口,该接口中声明可以被远程调用的方法
extends Remote
- 2. 在服务器端定义一个类实现该接口。注意,该接口必须
以及extends UnicastRemoteObject
throws RemoteException
- 3. 在服务器上创建上面写的类的对象,并实现rmi注册表的绑定,具体过程为:
RMIImplementation theRemote=new RMIImplementation();
LocateRegistry.createRegistry(1099);
Naming.rebind("theRemote",theRemote);
- 4. 在客户端获取该对象并使用其方法,具体过程为:
RMIInterface ri = (RMIInterface)Naming.lookup(rmi://localhost/theRemote);//注意此处lookup的内容必须与服务器bind的内容一致
System.setSecurityManager(new RMISecurityManager());//如果服务器和客户端不再同一台机器要加这行