LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 1 | #gRPC in 3 minutes (C++) |
Abhishek Kumar | 3a5592c | 2015-02-20 15:32:42 -0800 | [diff] [blame] | 2 | |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 3 | ## Installation |
4 | |||||
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 5 | To install gRPC on your system, follow the instructions to build from source |
6 | [here](../../INSTALL.md). This also installs the protocol buffer compiler | ||||
7 | `protoc` (if you don't have it already), and the C++ gRPC plugin for `protoc`. | ||||
Abhishek Kumar | 3a5592c | 2015-02-20 15:32:42 -0800 | [diff] [blame] | 8 | |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 9 | ## Hello C++ gRPC! |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 10 | |
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 11 | Here's how to build and run the C++ implementation of the [Hello |
12 | World](../protos/helloworld.proto) example used in [Getting started](..). | ||||
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 13 | |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 14 | ### Client and server implementations |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 15 | |
yang-g | b00a3f6 | 2015-08-28 14:19:37 -0700 | [diff] [blame] | 16 | The client implementation is at [greeter_client.cc](helloworld/greeter_client.cc). |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 17 | |
yang-g | b00a3f6 | 2015-08-28 14:19:37 -0700 | [diff] [blame] | 18 | The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc). |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 19 | |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 20 | ### Try it! |
Yang Gao | 3054eba | 2015-02-24 14:36:18 -0800 | [diff] [blame] | 21 | Build client and server: |
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 22 | |
Yang Gao | 3054eba | 2015-02-24 14:36:18 -0800 | [diff] [blame] | 23 | ```sh |
24 | $ make | ||||
25 | ``` | ||||
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 26 | |
Yang Gao | 84c263f | 2015-02-24 14:47:47 -0800 | [diff] [blame] | 27 | Run the server, which will listen on port 50051: |
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 28 | |
Yang Gao | 3054eba | 2015-02-24 14:36:18 -0800 | [diff] [blame] | 29 | ```sh |
30 | $ ./greeter_server | ||||
31 | ``` | ||||
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 32 | |
Yang Gao | ecee424 | 2015-02-24 14:46:53 -0800 | [diff] [blame] | 33 | Run the client (in a different terminal): |
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 34 | |
Yang Gao | 3054eba | 2015-02-24 14:36:18 -0800 | [diff] [blame] | 35 | ```sh |
36 | $ ./greeter_client | ||||
37 | ``` | ||||
David Garcia Quintas | 260a002 | 2016-08-09 16:57:32 -0700 | [diff] [blame^] | 38 | |
39 | If things go smoothly, you will see the "Greeter received: Hello world" in the | ||||
40 | client side output. | ||||
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 41 | |
42 | ## Tutorial | ||||
43 | |||||
yang-g | b00a3f6 | 2015-08-28 14:19:37 -0700 | [diff] [blame] | 44 | You can find a more detailed tutorial in [gRPC Basics: C++](cpptutorial.md) |