grpc安装:
由于工作需要,最近在学google的rpc开源框架;由于本人菜鸟一枚,而且是从Windows开发转到Linux;由于之前版本控制使用的是svn,没有使用过git,所以从GitHub上下载代码是通过浏览器下载zip格式的压缩文件,折腾了好几天了,发现了各种坑,各种缺少库,各种不知道怎么把这个库给装机器上。对于一个不熟悉Linux的人来说,这个体验简直糟糕透了。没办法了又在机器上装了git,按照下面这个链接从新安装,但惊喜就这么发生了,特么的居然可以安装上grpc!!!
grpc安装请参考该链接:https://blog.youkuaiyun.com/u012023606/article/details/54584282
其中有个文件我改了一下,因为之前装的时候碰到过缺少openssl这个库
测试代码:
测试代码参考该连接:https://blog.youkuaiyun.com/u012023606/article/details/54583526
上述链接中的Makefile文件第10行有问题,由于本人菜鸟,不知该怎么修改,故从githum上下载来的代码中的hello例子中拷贝了一个makefile过来并简单修改了一下。
example.proto:
syntax = "proto3";
message SearchRequest
{
string Request = 1;
}
message SearchResponse
{
string Response = 2;
}
service SearchService {
rpc Search (SearchRequest) returns (SearchResponse);
}
client.cpp:
#include <iostream>
#include <memory>
#include <string>
#include <grpc++/grpc++.h>
#include <grpc/support/log.h>
#include "example.grpc.pb.h"
using grpc::Channel;
using grpc::ClientAsyncResponseReader;
using grpc::ClientContext;
using grpc::CompletionQueue;
using grpc::Status;
class ExampleClient
{
public:
explicit ExampleClient(std::shared_ptr<Channel> channel)
: stub_(SearchService::NewStub(channel)) {}
std::