Mt client side uses sync API, as shown below.
class GreeterClient {
public:
GreeterClient(std::shared_ptr<Channel> channel)
: stub_(Greeter::NewStub(channel)) {}
// Assambles the client's payload, sends it and presents the response back
// from the server.
std::string SayHello(const std::string& user) {
// Data we are sending to the server.
HelloMessage request;
request.set_message(user);
// Container for the data we expect from the server.
HelloMessage reply;
// Context for the client. It could be used to convey extra information
to
// the server and/or tweak certain RPC behaviors.
ClientContext context;
std::shared_ptr<ClientReaderWriter<HelloMessage, HelloMessage> >
stream(stub_->SayHello(&context));
// The actual RPC.
stream->Write(request);
stream->Read(&reply);
return reply.message();
}
private:
std::unique_ptr<Greeter::Stub> stub_;
};
int main(int argc, char** argv) {
// Instantiate the client. It requires a channel, out of which the actual
RPCs
// are created. This channel models a connection to an endpoint (in this
case,
// localhost at port 50051). We indicate that the channel isn't
authenticated
// (use of InsecureChannelCredentials()).
GreeterClient greeter(grpc::CreateChannel(
"localhost:50051", grpc::InsecureChannelCredentials()));
std::string user("world");
std::string reply = greeter.SayHello(user);
std::cout << "Greeter received: " << reply << std::endl;
return 0;
}
Vijay Pai於 2017年1月24日星期二 UTC-8下午8時25分33秒寫道:
>
> What does your Client code look like?
>
>
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/808939a7-9335-4194-82af-4e92fadf04e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.