Reprinted from: https://www.cnblogs.com/ygj0930/p/6542811.html; add some of your own understanding;
One: RPC Remote Procedure Call (Note: You can understand that RPC is a common protocol for all languages, a bit like soap, and RMI is a Java implementation of RPC "or that RMI is the Java version of RPC requirements" This is your current understanding if there is an incorrect place to be able to point out)
RPC (remote Procedure call Protocol) Remoting procedure invoke protocol that requests a service from a remote computer over a network. (Note: It can be understood that, as long as it is through the network to adjust a remote service, then this is RPC, not necessarily the HTTP request, TCP request, UDP request, SOAP message request can be, let alone these several requests are related, So when you say that your distributed system communication is implemented via RPC, you can continue to ask what protocol/method is implemented for RPC)
the process of an RPC call is approximately 10 steps:
1. Execute client Call statement, transfer parameters
2. Call the local system to send a network message
3. Messaging to a remote host
4. The server gets the message and obtains the parameters
5. Executing remote procedures (services) based on call requests and parameters
6. The execution process is complete, returning the result to the server handle
7. The server handle returns the result, calling the remote host's system network service to send the results
8. Send the message back to the local host
9. Client handles receive messages from the local host's network service
10. The client receives the result data returned by the calling statement
II: RMI Remote Method Invocation (note: The axis framework is implemented based on RMI requirements because RMI is a refined version of the Java language of RPC, similar to the subclass version, so axis is also implementing RPC standards)
(Note: The stub is the client-generated stub in axis, and skeleton can be thought of as the servlet object of axis, which parses the SOAP message and finds the corresponding service and then invokes it)
RMI: Remote method call (invocation). Enables an object on a client Java virtual machine to invoke a method on an object in a server-side Java Virtual machine like a local object.
RMI Remote Invocation steps:
1, the client invokes the method on the helper object stub
2, client helper stub package call information (variable, method name), sent over the network to the server helper object skeleton
3, the server helper object skeleton the information sent by the client helper to find out the method that is actually called and the object where the method resides.
4, invoke the True method on the real service object and return the result to the server helper skeleton
5, the server helper object packages the results and sends them to the client helper stub
6, the client helper object will return the value of the unpacking, returned to the caller
7, the customer gets the return value
Three: The difference between RPC and RMI
1: Methods are called in different ways:
RMI is called by remote methods on the client's stub object as a remote interface . each remote method has a method signature . If a method executes on the server, but no matching signature is added to the remote interface (stub), the new method cannot be called by the RMI client .
(Note: All network communication is basically inseparable from the TCP protocol, here is actually a TCP protocol data transmission, and the server is to be able to parse this format of data , axis is manually defined by the framework of the data format)
(Note: There is a registry where RPC requests are processed on the server, where key is a package.class.method parameter that matches the parameters of the client and finds the corresponding method and calls)
RPC sends a request to a remote host over a network Service protocol , which contains a parameter set and a literal value, usually in the form of a "classname.methodname (parameter Set)". The RPC remote host searches for the matching classes and methods, finds the execution method and encodes the result, and sends it back through the network protocol.
2: The applicable language range is different:
RMI is used only in Java;
RPC is a network service protocol that is independent of the operating system and language.
(Note: RPC is a network protocol, this protocol format can be customized, as long as the client server to coordinate well, you can refer to https://baike.baidu.com/item/%E8%BF%9C%E7%A8%8B%E8%BF%87%E7%A8% 8b%e8%b0%83%e7%94%a8%e5%8d%8f%e8%ae%ae/6893245?fromtitle=rpc%e5%8d%8f%e8%ae%ae&fromid=5019569&fr= Aladdin; The protocol structure part to customize its own protocol data structure "such as the TCP protocol with two bytes as the length of the data, two bytes as the version of the Chant class is a protocol format implementation, their own smart data format is the entity of the Protocol is not called the RPC Protocol")
Note
The RPC information protocol consists of two different structures: invocation information and reply information. The information flow is as follows:
RPC: Remote procedure call Process RPC Call information: Each remote procedure call information includes the following unsigned integer field to independently identify the remote procedure: program number, the program version number, and process number (Procedure Number) The RPC call Information body form is as follows: struct call_body {unsigned int rpcvers;unsigned int prog;unsigned int vers;unsigned int Proc;opaque _auth cred;opaque_auth verf;1 parameter2 parameter ...} RPC Reply information: The RPC Protocol's response information changes depending on whether the network server is receiving or rejecting the call information. The reply request includes various information that distinguishes between the following scenarios: RPC successfully executes the invocation information. The remote implementation of RPC is not the second edition of the Protocol and returns the minimum and maximum version numbers supported by RPC. Remote programs are not available in the remote system. The requested version number is not supported by the remote program. Returns the minimum and maximum version numbers supported by the remote program. The requested procedure number does not exist. Usually a caller agreement or program error. The RPC reply information form is as follows: enum Reply_stat stat{msg_accepted = 0,msg_denied = 1};
)
3: The return form of the call result is different:
Java is object-oriented, so the result of RMI invocation can be object type or basic data type;
The result of RMI unification is represented by the external data representation (External data representation, XDR) language , which abstracts the differences between the byte order class and the data type structure.
The difference between Java RMI and RPC