Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
vrecluse opened this issue Dec 4, 2022 · 4 comments
Open

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

vrecluse opened this issue Dec 4, 2022 · 4 comments

Comments

@vrecluse
Copy link

vrecluse commented Dec 4, 2022

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

@ithewei
Copy link
Owner

ithewei commented Dec 4, 2022

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);

@ugenehan
Copy link

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);

@VAllens
Copy link

VAllens commented Dec 7, 2023

Is there any progress? :)

@VAllens
Copy link

VAllens commented Dec 7, 2023

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants