blob: 70418b44253a313480f5b1fa1fb90751b75d001a [file] [log] [blame] [view]
LisaFCd1e11e72015-02-23 18:16:08 +00001#gRPC in 3 minutes (C++)
Abhishek Kumar3a5592c2015-02-20 15:32:42 -08002
LisaFCd1e11e72015-02-23 18:16:08 +00003## Installation
4
5To install gRPC on your system, follow the instructions here:
Abhishek Kumaraa6c5fd2015-02-20 15:41:55 -08006[https://github.com/grpc/grpc/blob/master/INSTALL](https://github.com/grpc/grpc/blob/master/INSTALL).
Abhishek Kumar3a5592c2015-02-20 15:32:42 -08007
LisaFCd1e11e72015-02-23 18:16:08 +00008## Hello C++ gRPC!
Tim Emiola10135582015-02-23 09:22:26 -08009
Stanley Cheung0a268212015-08-27 14:38:38 -070010Here's how to build and run the C++ implementation of the [Hello World](examples/protos/helloworld.proto) example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples).
Tim Emiola10135582015-02-23 09:22:26 -080011
Stanley Cheung0a268212015-08-27 14:38:38 -070012The example code for this and our other examples lives in the `examples`
13directory. Clone this repository to your local machine by running the
Tim Emiola10135582015-02-23 09:22:26 -080014following command:
15
16
17```sh
Stanley Cheung0a268212015-08-27 14:38:38 -070018$ git clone https://github.com/grpc/grpc.git
Tim Emiola10135582015-02-23 09:22:26 -080019```
20
Stanley Cheung0a268212015-08-27 14:38:38 -070021Change your current directory to examples/cpp/helloworld
Tim Emiola10135582015-02-23 09:22:26 -080022
23```sh
Stanley Cheung0a268212015-08-27 14:38:38 -070024$ cd examples/cpp/helloworld/
Tim Emiola10135582015-02-23 09:22:26 -080025```
26
Tim Emiola10135582015-02-23 09:22:26 -080027
Tim Emiola10135582015-02-23 09:22:26 -080028### Generating gRPC code
29
Tim Emiola10135582015-02-23 09:22:26 -080030To generate the client and server side interfaces:
31
32```sh
Nicolas "Pixel" Nobleb6413de2015-04-10 00:24:09 +020033$ make helloworld.grpc.pb.cc helloworld.pb.cc
Tim Emiola10135582015-02-23 09:22:26 -080034```
35Which internally invokes the proto-compiler as:
36
37```sh
Nicolas "Pixel" Nobleb6413de2015-04-10 00:24:09 +020038$ protoc -I ../../protos/ --grpc_out=. --plugin=protoc-gen-grpc=grpc_cpp_plugin ../../protos/helloworld.proto
39$ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
Tim Emiola10135582015-02-23 09:22:26 -080040```
41
LisaFCd1e11e72015-02-23 18:16:08 +000042### Client and server implementations
Tim Emiola10135582015-02-23 09:22:26 -080043
Stanley Cheung0a268212015-08-27 14:38:38 -070044The client implementation is at [greeter_client.cc](examples/cpp/helloworld/greeter_client.cc).
Tim Emiola10135582015-02-23 09:22:26 -080045
Stanley Cheung0a268212015-08-27 14:38:38 -070046The server implementation is at [greeter_server.cc](examples/cpp/helloworld/greeter_server.cc).
Tim Emiola10135582015-02-23 09:22:26 -080047
LisaFCd1e11e72015-02-23 18:16:08 +000048### Try it!
Yang Gao3054eba2015-02-24 14:36:18 -080049Build client and server:
50```sh
51$ make
52```
Yang Gao84c263f2015-02-24 14:47:47 -080053Run the server, which will listen on port 50051:
Yang Gao3054eba2015-02-24 14:36:18 -080054```sh
55$ ./greeter_server
56```
Yang Gaoecee4242015-02-24 14:46:53 -080057Run the client (in a different terminal):
Yang Gao3054eba2015-02-24 14:36:18 -080058```sh
59$ ./greeter_client
60```
Yang Gaoecee4242015-02-24 14:46:53 -080061If things go smoothly, you will see the "Greeter received: Hello world" in the client side output.
LisaFCd1e11e72015-02-23 18:16:08 +000062
63## Tutorial
64
Stanley Cheung0a268212015-08-27 14:38:38 -070065You can find a more detailed tutorial in [gRPC Basics: C++](examples/cpp/cpptutorial.md)