The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#) https://grpc.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

10 years ago
#gRPC in 3 minutes (C++)
10 years ago
## Installation
10 years ago
To install gRPC on your system, follow the instructions [here](../../INSTALL).
10 years ago
10 years ago
## Hello C++ gRPC!
Here's how to build and run the C++ implementation of the [Hello World](../protos/helloworld.proto) example used in [Getting started](..).
10 years ago
The example code for this and our other examples lives in the `examples`
directory. Clone this repository to your local machine by running the
10 years ago
following command:
```sh
$ git clone https://github.com/grpc/grpc.git
10 years ago
```
Change your current directory to examples/cpp/helloworld
10 years ago
```sh
$ cd examples/cpp/helloworld/
10 years ago
```
### Generating gRPC code
To generate the client and server side interfaces:
```sh
$ make helloworld.grpc.pb.cc helloworld.pb.cc
10 years ago
```
Which internally invokes the proto-compiler as:
```sh
$ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto
$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
10 years ago
```
10 years ago
### Client and server implementations
The client implementation is at [greeter_client.cc](helloworld/greeter_client.cc).
10 years ago
The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc).
10 years ago
10 years ago
### Try it!
10 years ago
Build client and server:
```sh
$ make
```
10 years ago
Run the server, which will listen on port 50051:
10 years ago
```sh
$ ./greeter_server
```
10 years ago
Run the client (in a different terminal):
10 years ago
```sh
$ ./greeter_client
```
10 years ago
If things go smoothly, you will see the "Greeter received: Hello world" in the client side output.
10 years ago
10 years ago
## Tutorial
You can find a more detailed tutorial in [gRPC Basics: C++](cpptutorial.md)