`
eimhee
  • 浏览: 2151248 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Start PageIndexHistoryLast Change

阅读更多
The specifications should provide the developer with the information needed to implement the protocol.

NOTE: The JSON-RPC 2.0 Specification proposal has been published and open for review and comments.

Overview¶
JSON-RPC is a lightweight remote procedure call protocol. It's designed to be simple!

The general mechanism consists of two peers establishing a data connection. During the lifetime of a connection, peers may invoke methods provided by the other peer. To invoke a remote method, a request is sent. Unless the request is a notification it must be replied to with a response.

1.1 Request (method invocation)¶
A remote method is invoked by sending a request to a remote service. The request is a single object serialized using JSON.

It has three properties:

•method - A String containing the name of the method to be invoked.
•params - An Array of objects to pass as arguments to the method.
•id - The request id. This can be of any type. It is used to match the response with the request that it is replying to.
1.2 Response¶
When the method invocation completes, the service must reply with a response. The response is a single object serialized using JSON.

It has three properties:

•result - The Object that was returned by the invoked method. This must be null in case there was an error invoking the method.
•error - An Error object if there was an error invoking the method. It must be null if there was no error.
•id - This must be the same id as the request it is responding to.
1.3 Notification¶
A notification is a special request which does not have a response. The notification is a single object serialized using JSON.

It has the same properties as the request object with one exception.

•id - Must be null.
2.1 JSON-RPC over stream connections¶
The specifications do not require a certain transport protocol. The use of TCP/IP socket streams is encouraged. The serialized request and response objects are sent to the peers through the byte streams.

Requests and responses may be sent to a peer at any time. The peer must respond to each request unless it is a notification. A response may only be sent in reply to a request.

Closing the connection between peers must raise an exception for all unanswered requests on each peer. Non-valid requests or responses must result in closing the connection.

2.2 JSON-RPC over HTTP¶
With some limitation, HTTP requests can be used as a transport for communicating between peers.

A communication between peers, one being an HTTP client the other an HTTP server, may span multiple HTTP requests. A client side peer may send one or more requests, notifications or responses to its peer by sending an HTTP POST request containing all serialized objects.

The server side peer must reply with responses to all requests sent and may send requests or notifications of its own. The client side peer must reply to requests received by sending another HTTP POST.

To give the serverside peer a chance to send messages to the client side peer, the client side peer may reopen communication by sending an empty HTTP POST.

A non-valid request must result in closing the connection. A non-valid response must raise an exception for all unanswered requests on the client. Closing a connection must raise an exception for all unanswered requests on the client.

FIXME: Describe/define how sessions are handled, as there is no implicit session formed by a TCP-connection.

3. JSON Class hinting¶
There are only simple data types defined in JSON. To overcome this problem in a JSON compatible way a special property for objects is introduced.
{"__jsonclass__":["constructor", [param1,...]], "prop1": ...}
The object is then instantiated using the constructor, passing in the parameters. Once constructed the properties (prop1, ...) will be applied.

4. Communication Examples¶
--> data sent to service
<-- data coming from service

•service.echo("Hello JSON-RPC")
--> { "method": "echo", "params": ["Hello JSON-RPC"], "id": 1}
<-- { "result": "Hello JSON-RPC", "error": null, "id": 1}
•multiple request responses
This example shows parts of a communication from an example chat application. The chat service sends notifications for each chat message the client peer should receive. The client peer sends requests to post messages to the chat and expects a positive reply to know the message has been posted.

...

--> {"method": "postMessage", "params": ["Hello all!"], "id": 99}
<-- {"result": 1, "error": null, "id": 99}
<-- {"method": "handleMessage", "params": ["user1", "we were just talking"], "id": null}
<-- {"method": "handleMessage", "params": ["user3", "sorry, gotta go now, ttyl"], "id": null}
--> {"method": "postMessage", "params": ["I have a question:"], "id": 101}
<-- {"method": "userLeft", "params": ["user3"], "id": null}
<-- {"result": 1, "error": null, "id": 101}
...
分享到:
评论

相关推荐

    Windows 7 Start Button Change

    Windows 7的开始按钮非常漂亮,但看久了也会“审美疲劳”,这个名为Windows 7 Start Button Changer的小工具,就是用来替换开始按钮样式的。据说是一个12岁的小网民开发的。  用法非常简单,选择要替换的源文件,再...

    changeip的ddns更新客户端【curl实现changeip的ddns动态域名更新功能】

    通过批处理调用curl来进行changeip的ddns更新,解压到本地某路径,简单修改一下帐户和域名信息,点击start.bat直接运行即可。 参数说明: set user=用户名 set password=密码 set domain=你的ddns set url=...

    Change_Start_Time.rar_Selected

    标题“Change_Start_Time.rar_Selected”暗示我们这里涉及的宏功能是调整选定的约会或会议的开始时间。这个特定的宏可能对于那些需要批量更改日程安排的人来说非常有用,比如在调整工作时间表或者应对突发情况时。 ...

    start-stop-daemon

    linux系统命令start-stop-daemon的源码及二进制,其中也提供了一个服务启动脚本模板。 此程序能帮助你实现将命令行程序变成服务运行,比如将"java -jar xxx.jar" 放在后台执行。 ./start-stop-daemon --help start-...

    electron-quick-start-master 快速入门教程

    electron-quick-start-master 快速入门教程electron-quick-start-master 快速入门教程electron-quick-start-master 快速入门教程electron-quick-start-master 快速入门教程electron-quick-start-master 快速入门教程...

    oracle数据库startwith用法

    ### Oracle数据库中的START WITH 和 CONNECT BY 用法详解 在Oracle数据库中,处理层次结构数据时,`START WITH` 和 `CONNECT BY` 是非常有用的两个关键字。这些关键字可以帮助我们在查询时构建出树形或者层级结构的...

    Cadence17.4禁止启动Start Page开始页面方法

    ### Cadence17.4禁止启动Start Page开始页面方法 #### 一、概述 Cadence17.4是一款广泛应用于电子设计自动化领域的软件工具,它包括了多种EDA(电子设计自动化)工具,如ORCAD、Allegro等,用于电路设计、仿真、...

    Win10开始菜单修复工具Windows 10 Start Menu TroubleShooter下载

    Start Menu does not open or not working in Windows 10 Win10开始菜单修复工具Windows 10 Start Menu TroubleShooter下载 这个微软官方Win10开始菜单修复工具是一个单文件的大小只有398KB的小工具,文件名为start...

    使用StartUML绘制类图

    使用StartUML绘制类图 在软件开发过程中,类图是UML(Unified Modeling Language)中最重要的一种图表,用于描述系统中类之间的关系和结构。StartUML是一个功能强大且易用的UML建模工具,适合用于绘制类图。下面将...

    HP服务器windows下SmartStart_光盘自动安装驱动安装驱动.doc

    《HP服务器SmartStart光盘驱动安装详解》 HP服务器SmartStart是一种智能化的工具,它旨在简化服务器的初始配置、操作系统安装以及驱动程序的部署过程。本文以Proliant DL380 G3服务器和SmartStart 7.1版本光盘为例...

    spring boot/spring cloud项目启动脚本,默认名称:start.sh

    linux服务器,springboot,spring cloud、spring ...sh start.sh start sh start.sh stop sh start.sh restart sh start.sh status 或者: ./start.sh start ./start.sh stop ./start.sh restart ./start.sh status

    打印机驱动 实达Start BP-750KII 驱动

    打印机驱动 实达Start BP-750KII 驱动打印机驱动 实达Start BP-750KII 驱动打印机驱动 实达Start BP-750KII 驱动打印机驱动 实达Start BP-750KII 驱动打印机驱动 实达Start BP-750KII 驱动打印机驱动 实达Start BP-...

    startuml.zip

    《startuml.zip——快速入门UML建模工具StartUML》 在软件开发过程中,UML(统一建模语言)是一种强大的工具,用于可视化、规格化和构建软件系统。StartUML是开源的UML建模工具,它提供了一种简单易用的方式来创建...

    HP_Easy_Start.app.zip 惠普打印机客户端驱动

    【HP Easy Start.app.zip - 惠普打印机客户端驱动】 HP Easy Start 是一款由惠普公司专门为Mac用户设计的应用程序,用于简化安装惠普打印机驱动的过程。这个压缩包文件`HP_Easy_Start.app.zip`包含了该应用程序的...

    startdelay_v2.3服务器启动延迟

    《服务器启动延迟——深入解析startdelay_v2.3》 在服务器管理领域,优化系统启动流程以确保服务的稳定性和高效性是至关重要的。本文将深入探讨“startdelay_v2.3”这一工具,它是针对服务器启动延迟问题的解决方案...

    CentOS7 service network start命令启动时报错解决方法

    CentOS7 service network start命令启动时报错解决方法 在 CentOS7 中,当我们使用 `service network start` 命令启动网络服务时,可能会遇到启动失败的问题。这是因为 CentOS7 中的网络服务启动机制已经改变,需要...

    javafx-textfield-change-demo

    本示例"javafx-textfield-change-demo"就是关于如何实现这一功能的演示。 JavaFX提供了事件处理机制,我们可以使用ChangeListener接口来监听TextField的文本变化。当TextField中的文本发生改变时,ChangeListener的...

    startServer.sh

    startServer.sh

    打印机驱动 实达Start BP-690K+ 驱动

    打印机驱动 实达Start BP-690K+ 驱动打印机驱动 实达Start BP-690K+ 驱动打印机驱动 实达Start BP-690K+ 驱动打印机驱动 实达Start BP-690K+ 驱动打印机驱动 实达Start BP-690K+ 驱动打印机驱动 实达Start BP-690K+ ...

Global site tag (gtag.js) - Google Analytics