Ok, I create patch:
http://www.bspdev.ru/jsonrpc-patch.zipPatch created using WinMerge software
www.winmerge.orgHow to use:
1. Appy patach to RTC SDK sources. Version supported: RealThinClientSDK_v737_2016Q3.zip
2. Look at rtcDefs.inc, here is new define: {$DEFINE RTC_SUPPORT_JSONRPC}, enable it for JSON-RPC 2.0 support
3. Compile packages.
Now you can select fmt_JSONRPC dataformat for RtcClientModule and RtcServerModule.
Usage details: you can call remote functions same way as with fmt_RTC and fmt_XMLRPL with some exceptions:
According to JSON-RPC 2.0 specification each json-rpc request should contain "id" with unique value. To set "id" for your requests you have this options:
1. TRtcClientModule.JsonRpcAutoId property. If set to true guid string will be generated and used as id automatically:
{"jsonrpc": "2.0", "method": "myfunc", "params": [42, 23], "id": "{644e1dd7-2a7f-18fb-b8ed-ed78c3f92c2b}"}
2. TRtcFunctionInfo.JsonRpcRequestID property. Using this property you can set request id manually:
with RtcClientModule1 do
begin
with Prepare('MyFunc') do
begin
JsonRpcRequestID:='myId12345';
....
end;
end;
it's produce request like this: {"jsonrpc": "2.0", "method": "myfunc", "params": [42, 23], "id": "myId12345"}
If TRtcClientModule.JsonRpcAutoId=false and you not set id via TRtcFunctionInfo.JsonRpcRequestID - id field will be ommited. According to JSON-RPC 2.0 specification requests without "id" field will be considered as "notification" and empty response will be send from server (in case of errors to) !
Finally, request id must be unique if you send many requsts in batch using TRtcClientModule.StartCalls/Post. In case of duplicate exception will be raised.
If your remote functions fails you can send back error by raising exception in your TRtcFunction.OnExecute handler. Error code and message must be in same string with # and : symbols as separators:
raise Exception.Create('#25:MyFinc execute failed');
this generate response like this:
{"jsonrpc": "2.0", "error": {"code": 25, "message": "MyFunc execute failed"}, "id": "myId12345"}
It's inspired by current Danijel implementation )
Another important note: do not call delayed function in batch using StartCalls/Post ! It's not supported because responses must be also in batch but delayed function will send individual responses.
Finally, here is one feature of json-rpc 2.0 wich is not implemented: if you send many requests in batch and one of request is bad:
[{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
{"jsonrpc": "2.0", "method": "NotExists", "params": [1,2,4], "id": "2"}, // call of non exist remote function
{"jsonrpc": "2.0", "method": "MyFunc", "params": [1,2,4], "id": "3"}]
According to json-rpc 2.0 specification server must send responses for each request in batch. In my implementation server stop processing batch after first error. For example above they send response for request 1, send error response for request2 and skip request 3. It's caused by current Danijel's json parsing implementation (processing requests one by one and stop on any exception). It's can be fixed by pre-parsing entire batch but it's require complete rewrite of TRtcBaseServerModule.Call_DataReceived function.
Enjoy )