哈尔滨有多少家网站建设公司,百度官方网站下载,视频拍摄和剪辑怎么学,新闻资讯型网站开发简述你对RPC、RMI的理解
RPC#xff1a;在本地调用远程的函数#xff0c;远程过程调用#xff0c;可以跨语言实现 httpClient
RMI#xff1a;远程方法调用#xff0c;java中用于实现RPC的一种机制#xff0c;RPC的java版本#xff0c;是J2EE的网络调用机制#xff0c…简述你对RPC、RMI的理解
RPC在本地调用远程的函数远程过程调用可以跨语言实现 httpClient
RMI远程方法调用java中用于实现RPC的一种机制RPC的java版本是J2EE的网络调用机制跨JVM调用对象的方法面向对象的思维方式
直接或间接实现接口 Java.rmi.Remote 成为存在于服务器端的远程对象供客户端访问并提供一定的服务
远程对象必须实现java.rmi.server.UniCastRemoteObject类这样才能保证客户端访问获得远程对象时该远程对象将会把自身的一个拷贝以Socket的形式传输给客户端此时客户端所获得的这个拷贝称为“存根”而服务器端本身已存在的远程对象则称之为骨架。其实此时的存根是客户端的一个代理用于与服务器端的通信而骨架也可认为是服务器端的一个代理用于接收客户端的请求之后调用远程方法来响应客户端的请求。
public interface IService extends Remote{String service(String content) throws RemoteException;
}public class ServiceImpl extends UnicastRemoteObject implements IService {private String name;public ServiceImpl (String name) throws RemoteException{this .name name;}overridepublic String service(String content) {return server content;}
}pub1ic class Server (public static void main(String [] args) {try {IService service02 new ServiceImpl (service02);Context namingContext new InitialContext();namingContext.rebind(rmi://127.0.0.1/service02service02);} catch (Exception e) {e.printstackTrace()}system.out.print7n(000000! );}
}pub1ic class Client (public static void main(String [] args) {string ur1 rmi://127 .0.0.1/;try {Context namingContext new InitialContext();IService service02 (IService)namingContext.lookup(urlservice02);Class stubClass service02.getClass();System.out.printIn(service02 is stubClass.getName());Class[] interfaces stubClass .getinterfaces();for (Class c : interfaces){System,out.printIn(implement c,getName() interface);}System.out.print1n(service02.service(he11o));} catch (Exception e) {e.printstackTrace()}}
}