Skip to main content

Client Interaction

The communication method between Client Plugin and Controller Plugin. Users can use TCP/RPC and other frameworks to implement in the Plugin, or use Rokae's built-in JSON format communication protocol. Client Interaction

Send protocol through Client Plugin, Controller Plugin receives and processes the protocol. This section introduces how to use the built-in communication protocol to implement communication.

    #include "service/service_api.hpp"

/**
* @brief Plugin name, Plugin key, callback function
* @note Controller will call the corresponding function when receiving json protocol
* User received protocol data is {"key":"value"}
*/
xcore_api::service::RegServiceAPI("example","get",
[](const Json::Value &in){
LOG_INFO<<"receive:"<<json_serialize(in);
// simu user process
std::this_thread::sleep_for(std::chrono::seconds(1));
Json::Value out;
out["return"] = "0";
return out;
});

Users send protocol in Client Plugin, Plugin name example, json data. Through the interface, the corresponding json data will be sent to the Plugin. Json data received by Plugin example:

{"key":" user json"}

Json data returned to Client Plugin:

{"key":" user return json"}

Client Interaction Result

Can refer to examples/service.hpp