In the past few days, I learned that JSON-RPC protocol, I feel that it is better, and I have made some notes based on the English documentation for reference.
The JSON-RPC protocol is a remote procedure call protocol that is designed to simplify processing. Conventional processing mechanism is in two pairs
A point-to-point data connection is established between the communication entity, and the other party may call the other party in the connected life cycle, in order to call a remote
The method must send a request, and the server side must answer a response relative to the request unless this request is a notification.
1.1 Request (Method Invocation)
The client implements the call to the remote method by sending a request to the remote service, and this request is serialized by JSON protocol
The object contains the following three properties:
· Method: Call method name;
• Params: Parameter list of called methods;
• ID: The request ID can be any type for matching the response.
1.2 Response
When the method call is completed, the server must give a response, and this response is also a JSON protocol serialized object, which contains three properties:
· Result: is an object returned by the called method. If the error is called, its value is NULL;
· Error: If there is no error call method, its value is NULL;
· ID: The same ID is the same as the request to be responded.
1.3 Notification
A NOTIFICATION request is a special request for a response, which is also a TSON protocol serial, containing the same properties as the general request, but its ID should be NULL.
2.1JSON-RPC over Stream Connection
This specification does not require a specific transport protocol, and encourages the transmission of streams using TCP / IP. At any time, it is possible to perform a serialized request and response object between transport entities. For all requests other than NOTIFICATION requests, the other end of communication is given a response. An illegal request or response will cause the connection to the two sides, while it will also generate an abnormality because each end of the communication is abnormal.
2.2JSON-RPC over http
It can also be used to communicate with the service for HTTP. The client can send one or more requests to the server, all requests must be sent as an HTTP POST object containing all series request objects, and the answer must contain a series of responses to all requests, Nofife can be Or send out on the server side.
Similarly, an illegal request will cause the connection to disconnect, and an illegal response will also generate an exception in the client, and close the connection will also generate an exception in the client.
3. JSON Class Hinting
JSON object format:
{"JSONCLASS": ["constructor", [param1,], "prop1": ...]}