1 Star 0 Fork 51

ryvius_key / srpc

forked from 搜狗开源 / srpc 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
tutorial-04-client.md 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
liyingxin 提交于 2021-06-20 22:25 . update docs

中文版

RPC Client

  • Each Client corresponds to one specific target/one specific cluster
  • Each Client corresponds to one specific network communication protocol
  • Each Client corresponds to one specific IDL

Sample

You can follow the detailed example below:

  • Following the above example, the client is relatively simple and you can call the method directly.
  • Use Example::XXXClient to create a client instance of some RPC. The IP+port or URL of the target is required.
  • With the client instance, directly call the rpc function Echo. This is an asynchronous request, and the callback function will be invoked after the request is completed.
  • For the usage of the RPC Context, please check RPC Context.
#include <stdio.h>
#include "example.srpc.h"

using namespace srpc;

int main()
{
    Example::SRPCClient client("127.0.0.1", 1412);
    EchoRequest req;
    req.set_message("Hello, sogou rpc!");
    req.set_name("Li Yingxin");

    client.Echo(&req, [](EchoResponse *response, RPCContext *ctx) {
        if (ctx->success())
            printf("%s\n", response->DebugString().c_str());
        else
            printf("status[%d] error[%d] errmsg:%s\n",
                    ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg());
    });

    pause();
    return 0;
}
C++
1
https://gitee.com/ryvius_key/srpc.git
git@gitee.com:ryvius_key/srpc.git
ryvius_key
srpc
srpc
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891