Skip to content
Snippets Groups Projects
README.md 1.54 KiB
Newer Older
LisaFC's avatar
LisaFC committed
#gRPC in 3 minutes (C++)
Abhishek Kumar's avatar
Abhishek Kumar committed

LisaFC's avatar
LisaFC committed
## Installation
Tim Emiola's avatar
Tim Emiola committed

To install gRPC on your system, follow the instructions [here](../../INSTALL.md).
Tim Emiola's avatar
Tim Emiola committed

LisaFC's avatar
LisaFC committed
## Hello C++ gRPC!

yang-g's avatar
yang-g committed
Here's how to build and run the C++ implementation of the [Hello World](../protos/helloworld.proto) example used in [Getting started](..).
Tim Emiola's avatar
Tim Emiola committed

The example code for this and our other examples lives in the `examples`
directory. Clone this repository to your local machine by running the
Tim Emiola's avatar
Tim Emiola committed
following command:


```sh
$ git clone https://github.com/grpc/grpc.git
Tim Emiola's avatar
Tim Emiola committed
```

Change your current directory to examples/cpp/helloworld
Tim Emiola's avatar
Tim Emiola committed

```sh
$ cd examples/cpp/helloworld/
Tim Emiola's avatar
Tim Emiola committed
```


### Generating gRPC code

To generate the client and server side interfaces:

```sh
$ make helloworld.grpc.pb.cc helloworld.pb.cc
Tim Emiola's avatar
Tim Emiola committed
```
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
Tim Emiola's avatar
Tim Emiola committed
```

LisaFC's avatar
LisaFC committed
### Client and server implementations

yang-g's avatar
yang-g committed
The client implementation is at [greeter_client.cc](helloworld/greeter_client.cc).
LisaFC's avatar
LisaFC committed

yang-g's avatar
yang-g committed
The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc).
Tim Emiola's avatar
Tim Emiola committed

LisaFC's avatar
LisaFC committed
### Try it!
Yang Gao's avatar
Yang Gao committed
Build client and server:
```sh
$ make
```
Yang Gao's avatar
Yang Gao committed
Run the server, which will listen on port 50051:
Yang Gao's avatar
Yang Gao committed
```sh
$ ./greeter_server
```
Yang Gao's avatar
Yang Gao committed
Run the client (in a different terminal):
Yang Gao's avatar
Yang Gao committed
```sh
$ ./greeter_client
```
Yang Gao's avatar
Yang Gao committed
If things go smoothly, you will see the "Greeter received: Hello world" in the client side output.
Tim Emiola's avatar
Tim Emiola committed

LisaFC's avatar
LisaFC committed
## Tutorial
Abhishek Kumar's avatar
Abhishek Kumar committed

yang-g's avatar
yang-g committed
You can find a more detailed tutorial in [gRPC Basics: C++](cpptutorial.md)