libhv icon indicating copy to clipboard operation
libhv copied to clipboard

有 GRPC 客户端完整的使用例子吗?

Open vrecluse opened this issue 3 years ago • 4 comments

Only grpc server sample found in this repository. Is the official grpc c++ library required?

vrecluse avatar Dec 04 '22 06:12 vrecluse

libhv里集成了nghttp2实现http2协议,而grpc是基于http2的,所以理论上是可以实现grpc的,但是因为grpc绑定了protobuf,通过IDL文件自动生成序列化/反序列化代码,这步libhv还没有很好的集成。

目前可访问grpc服务的步骤为: 1、编译时带上nghttp2

./configure --with-nghttp2
make

2、请求协议采用http2,content-type设置为application/grpc

HttpRequest req;
req.http_major = 2;
req.http_minor = 0;
req.content_type = APPLICATION_GRPC;

3、请求body使用protobuf序列化

req.body = SerializeAsString(xxx);

ithewei avatar Dec 04 '22 08:12 ithewei

HttpRequest req; req.http_major = 2; req.http_minor = 0; req.content_type = APPLICATION_GRPC; req.method = HTTP_POST; req.body = SerializeAsString(xxx);

HttpResponse res; hv::HttpClient client("0.0.0.0",12343); client.send(&req,&res);

ugenehan avatar Feb 10 '23 09:02 ugenehan

Is there any progress? :)

VAllens avatar Dec 07 '23 14:12 VAllens

Using the WebSocketClient::send(const char* buf, int len, enum ws_opcode opcode) method.

Example:

char* message = your protobuf serialize code....;
send(message, message.size(), WS_OPCODE_BINARY);

VAllens avatar Dec 07 '23 15:12 VAllens