mirror of
https://github.com/unclechu/gRPC-haskell.git
synced 2024-11-19 01:29:42 +01:00
e4a28e9e4b
* remove parent ptr from unregistered calls -- unneeded * begin unregistered high level server loop * undo changes to highlevel server, add mkConfig for unregistered server * move call CQ create/destroy into call create/destroy * async normal call function * preliminary unregistered server loop for non-streaming methods * working unregistered highlevel example * loop counters for benchmarking * changes for benchmarking, add ruby example server for benchmarking * async version of withCall, refactor unregistered server loop to handle all method types * unregistered client streaming * add remaining streaming modes * unregistered server streaming test * unregistered streaming tests * add error logging * fix bug in add example * remove old TODOs * fix bug: don't assume slices are null-terminated * add TODO re: unregistered client streaming functions
74 lines
1.4 KiB
C++
74 lines
1.4 KiB
C++
#include <string>
|
|
#include <iostream>
|
|
|
|
#include <grpc++/grpc++.h>
|
|
|
|
#include "echo.grpc.pb.h"
|
|
|
|
using namespace std;
|
|
using namespace echo;
|
|
using grpc::Channel;
|
|
using grpc::ClientContext;
|
|
using grpc::Status;
|
|
|
|
class EchoClient {
|
|
public:
|
|
EchoClient(shared_ptr<Channel> chan) : stub_(Echo::NewStub(chan)) {}
|
|
|
|
Status DoEcho(const string& msg){
|
|
EchoRequest req;
|
|
req.set_message(msg);
|
|
|
|
EchoRequest resp;
|
|
|
|
ClientContext ctx;
|
|
|
|
return stub_->DoEcho(&ctx, req, &resp);
|
|
}
|
|
|
|
private:
|
|
unique_ptr<Echo::Stub> stub_;
|
|
};
|
|
|
|
class AddClient {
|
|
public:
|
|
AddClient(shared_ptr<Channel> chan) : stub_(Add::NewStub(chan)) {}
|
|
|
|
AddResponse DoAdd(const uint32_t x, const uint32_t y){
|
|
AddRequest msg;
|
|
msg.set_addx(x);
|
|
msg.set_addy(y);
|
|
|
|
AddResponse resp;
|
|
|
|
ClientContext ctx;
|
|
|
|
stub_->DoAdd(&ctx, msg, &resp);
|
|
|
|
return resp;
|
|
}
|
|
private:
|
|
unique_ptr<Add::Stub> stub_;
|
|
};
|
|
|
|
int main(){
|
|
|
|
EchoClient client(grpc::CreateChannel("localhost:50051",
|
|
grpc::InsecureChannelCredentials()));
|
|
string msg("hi");
|
|
/*
|
|
while(true){
|
|
Status status = client.DoEcho(msg);
|
|
if(!status.ok()){
|
|
cout<<"Error: "<<status.error_code()<<endl;
|
|
return 1;
|
|
}
|
|
}
|
|
*/
|
|
|
|
AddClient addClient (grpc::CreateChannel("localhost:50051",
|
|
grpc::InsecureChannelCredentials()));
|
|
AddResponse answer = addClient.DoAdd(1,2);
|
|
cout<<"Got answer: "<<answer.answer()<<endl;
|
|
return 0;
|
|
}
|