当前位置:网站首页>Openharmony gnawing paper growth plan -- json-rpc
Openharmony gnawing paper growth plan -- json-rpc
2022-06-28 05:52:00 【Go to bed when you're done】
OpenHarmony Gnawing paper growth plan ---JSON-RPC
reference
introduction
Recently in to see JSON Relevant literature and materials , I also wrote two articles before JSON Related articles ( Interested students can go and have a look ):
OpenHarmony Gnawing paper growth plan — Why? JSON Will gradually replace XML?
OpenHarmony Gnawing paper growth plan — Several common JSON Parser comparison
Like me, there are a little small programs or web The development experience will be right JSON Familiar with , Because our front end often formats the information as JSON, Then call the back-end API Data transfer , We also know clearly web service That set is basically based on HTTP Agreed , The occasional use is socket communicate . But recently, I am learning mobile phone APP Development of , And came into contact with some Distributed system , Find out JSON It can also be done through RPC As a data exchange format for distributed systems , This is what this article will describe , be called JSON-RPC.
RPC
Let's find out what is RPC, I believe everyone will be confused RPC and HTTP, In fact, they are not the same level of concept ,RPC : Remote Procedure Call , In fact, it is a very broad concept name , Which translates as Remote procedure call , To put it bluntly, one machine remotely calls and executes functions on another machine . and HTTP It's a protocol ,HTTP It belongs to a kind of RPC How to implement .
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-aXcmEfFs-1644916839969)(JSON-RPC/resize,w_820,h_732.png)][ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-aJURTzcH-1644916839970)(https://harmonyos.51cto.com/posts/FAcallPA-%E4%B8%89/image-20220214130009214.png)]
stay HarmonyOS It's used in a lot of places RPC Means of communication , For example, cross device calls , Remote pull up FA,FA And so on .
JSON-RPC
Abstract
General applications require information from parties other than local . But these applications may use different systems or platforms .web There is a technology that can be used in development , Often referred to as web service. And in applications ,JSON-RPC yes web service One of the alternatives to . For example, there are two applications for information exchange , In the process of information transmission , Applications can perform business from remote back-end servers , To realize the direct communication between the two programs , By using JSON-RPC To achieve web service . Principle diagram :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-jMBTvODk-1644916839971)(JSON-RPC/image-20220215162051359.png)]
What is? JSON-RPC?
RPC Is a simple protocol framework , So it can be used to build a system based on web New agreement for the services of .RPC Allow an application to call a subprocess of another program on a different system remotely ,RPC Use a specific data exchange format in the transfer of data , Such as XML or JSON, As an adhesive between systems . The format of data exchange during transmission is JSON Format Of RPC agreement It's called JSON-RPC.
The official definition is :JSON-RPC Is a stateless lightweight RPC agreement . That is to say JSON-RPC It's a kind of Remote procedure call protocol . The usual processing mechanism is to establish a point-to-point data connection between two communication entities , During the life cycle of the connection , One party may call methods provided by the other party , Client sends a request , The server side gives the corresponding response . Its principle is shown in the figure :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-dLxodRx7-1644916839971)(JSON-RPC/image-20220215160726689.png)]
JSON-RPC Data structure of
For example, now we need to implement a subtraction function , The data structure passed between the server and the local is very simple , as follows :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-j5UQeEsy-1644916839973)(JSON-RPC/image-20220215150244310.png)]
essentially , Request is through Method name 、 Parameters and only id Sent .id Very important , Especially when a distributed system processes multiple requests from multiple sources , Because it tells the requested system where the request came from , Only in this way can the response result be sent to the correct requester .
JSON-RPC And HTTP The difference between
First look at HTTP,http Service you need to give the corresponding interface address , Need to define http method wait
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-dig5wVkV-1644916839974)(JSON-RPC/image-20220215164714387.png)]
however JSON-RPC Unwanted , Because in calling JSON-RPC The client has passed the method name , And the requestor's id, Or the example above :
[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-pUHrLAYf-1644916839975)(JSON-RPC/image-20220215164524868.png)]
therefore rpc It is more like daily communication between acquaintances , and http Like an agreement between strangers ,RPC( Include JSON-RPC) Invocation time , Already know who you are , What does it look like , Where are the things , And I know you allowed him to use it , You can use it directly . and http You need to communicate with strangers in advance , Discuss how to borrow and use other people's things , Can be used .
边栏推荐
- Simple handwritten debounce function
- YYGH-7-用户管理
- The length of pytorch dataloader the difference between epoch and iteration
- Important basis for ERP software company selection
- [CAD drawing Video] AutoCAD 2014 master's way
- 深度學習19種損失函數
- Mysql-17- create and manage tables
- Using pytorch and tensorflow to calculate the confusion matrix of classification model
- YYGH-8-预约挂号
- pkg打包node工程(express)
猜你喜欢
随机推荐
File foundation - read / write, storage
电商转化率这么抽象,到底是个啥?
JSP connects with Oracle to realize login and registration (simple)
Mysql-17- create and manage tables
Oracle 常用基础函数
Application of Beidou No.3 short message terminal in dam safety monitoring scheme
A full set of excellent SEO tutorials worth 300 yuan [159 lessons]
Valueerror: iterative over raw text documents expected, string object received
qtcanpool 知 07:Ribbon
阴阳师页面
What are the advantages of e-mail marketing? Why do sellers of shopline independent station attach so much importance to it?
数据中台:AI中台的实施与总结
YYGH-BUG-03
6. graduation design temperature and humidity monitoring system (esp8266 + DHT11 +oled real-time upload temperature and humidity data to the public network server and display the real-time temperature
Filecoin hacker song developer competition
Mysql-16-subquery
预训练模型参数不匹配
Jdbc的使用
6. 毕业设计温湿度监控系统(ESP8266 + DHT11 +OLED 实时上传温湿度数据给公网服务器并在OLED显示屏上显示实时温湿度)
PKG package node project (express)









