Position: Home page » Equipment » Calling mining with jsonrpc

Calling mining with jsonrpc

Publish: 2021-05-27 01:56:53
1. Send according to the standard JSON string format

JSON RPC is a standard
wiki.geekdream.com/specification/json RPC_ 2.0. HTML
here is the official document of 2.0. In addition, the package for parsing needs to be introced
2. jsonrpc = new JSONRpcClient("/ json-rpc"); // Instantiate JSON remote call
3. jQuery.post(url, [data], [callback], [type]
$.post(" test.php" name: " John" time: " 2pm"});
4. JSONObject jsonObject = new JSONObject();
Map map = request.getParameterMap();
Iterator<?> it = map.keySet().iterator();
while(it.hasNext()){
String key = (String)it.next();
String[] values = (String[])map.get(key);
jsonObject.accumulate(key, values[0]);
}

String name = jsonObject.getString("userName"); //返回从前台接受的用户名
System.out.println(name); //输出用户名

jsonObject.clear(); // 清空jsonObjec中的数据
jsonObject.put("love" , "足球"); //将足球赋给love这个变量名
out.print(jsonObject); //返回json格式的数据
5. Json-rpc-java is composed of two components for user visualization. They are jsonrpcbridge and jsonrpcservlet. The coordination of the two components realizes the processing of request objects by JSON server and responds to users
jsonrpcbridge is a session object that has the reference of the object exported from the server to a specific client. It receives the json-rpc request from the server (that is, jsonrpcservelet), and then decodes the JSON object into Java object, and then plays the role of method call, In addition, the Java object result group code (Marshall) returned by the method call is passed to the client for processing as a JSON object. The specific type conversion from Java object to JavaScript object is handled by serializer, which is responsible for serialization

jsonrpcbridge must be placed in the httpsession object, and the registered property name is "jsonrpcbridge", so that jsonrpcservlet can locate the bridge responsible for calling Java objects exported to the client. Therefore, in order to export all instances and static methods of an object to the client, you should have the following code: jsonrpcbridge. Registerobject (& quot; myObject", myObject)

in order to export all static methods of a class, you should: jsonrpcbridge. Registerclass (& quot; myObject", myObject)

if registerobject and registerclass are called multiple times to be used by objects with the same key value, they will be updated by the latest assigned object

in JSON, you can also use global bridge in singleton mode to export all instance methods for all HTTP clients. It can be used to register factory class, but we should pay attention to authentication and security when using it. When used, the identifier is as follows: jsonrpcbridge. Getglobalbridge(). Registerobject (& quot; myObject", myObject); As above, it can also export all static methods

the most important part of this protocol is servlet. Now let's briefly introce it:

in this protocol, jsonrpcservelet acts as a transmitter to process the JSON transmitted over HTTP
6. 服务端示例:
<?php
namespace Rpc\Controller;
use Think\Controller\JsonRpcController;
class JsonApiController extends JsonRpcController
{
public function index(){
return 'Hello, JsonRPC!';
}
// 支持参数传入
public function test($name=''){
return "Hello, {$name}!";
}
}
客户端示例:
vendor('jsonRPC.jsonRPCClient');
$client = new \jsonRPCClient('http://www.tp.cn/index.php/Rpc/JsonApi');
$result = $client->index();
var_mp($result); // 结果:Hello, JsonRPC!
$result = $client->test('deeka');
var_mp($result); // 结果:Hello, deeka!
7. I'm not God
8. You have to find daily tasks in daily tasks, and you need to complete other main tasks. You can't do it all the way according to tasks. You can't do it without the central task of floor cabinet. You won't be promoted to level 90 in Grundy, will you?
Hot content
Inn digger Publish: 2021-05-29 20:04:36 Views: 341
Purchase of virtual currency in trust contract dispute Publish: 2021-05-29 20:04:33 Views: 942
Blockchain trust machine Publish: 2021-05-29 20:04:26 Views: 720
Brief introduction of ant mine Publish: 2021-05-29 20:04:25 Views: 848
Will digital currency open in November Publish: 2021-05-29 19:56:16 Views: 861
Global digital currency asset exchange Publish: 2021-05-29 19:54:29 Views: 603
Mining chip machine S11 Publish: 2021-05-29 19:54:26 Views: 945
Ethereum algorithm Sha3 Publish: 2021-05-29 19:52:40 Views: 643
Talking about blockchain is not reliable Publish: 2021-05-29 19:52:26 Views: 754
Mining machine node query Publish: 2021-05-29 19:36:37 Views: 750