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 | |
Lisa Carey | 3be6801 | 2016-03-08 17:47:14 +0000 | [diff] [blame] | 5 | To install gRPC on your system, follow the instructions to build from source [here](../../INSTALL.md). This also installs the protocol buffer compiler `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] | 6 | |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 7 | ## Hello C++ gRPC! |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 8 | |
yang-g | b00a3f6 | 2015-08-28 14:19:37 -0700 | [diff] [blame] | 9 | Here's how to build and run the C++ implementation of the [Hello World](../protos/helloworld.proto) example used in [Getting started](..). |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 10 | |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 11 | The example code for this and our other examples lives in the `examples` |
| 12 | directory. Clone this repository to your local machine by running the |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 13 | following command: |
| 14 | |
| 15 | |
| 16 | ```sh |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 17 | $ git clone https://github.com/grpc/grpc.git |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 18 | ``` |
| 19 | |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 20 | Change your current directory to examples/cpp/helloworld |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 21 | |
| 22 | ```sh |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 23 | $ cd examples/cpp/helloworld/ |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 24 | ``` |
| 25 | |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 26 | ### Client and server implementations |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 27 | |
yang-g | b00a3f6 | 2015-08-28 14:19:37 -0700 | [diff] [blame] | 28 | The client implementation is at [greeter_client.cc](helloworld/greeter_client.cc). |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 29 | |
yang-g | b00a3f6 | 2015-08-28 14:19:37 -0700 | [diff] [blame] | 30 | The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc). |
Tim Emiola | 1013558 | 2015-02-23 09:22:26 -0800 | [diff] [blame] | 31 | |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 32 | ### Try it! |
Yang Gao | 3054eba | 2015-02-24 14:36:18 -0800 | [diff] [blame] | 33 | Build client and server: |
| 34 | ```sh |
| 35 | $ make |
| 36 | ``` |
Yang Gao | 84c263f | 2015-02-24 14:47:47 -0800 | [diff] [blame] | 37 | Run the server, which will listen on port 50051: |
Yang Gao | 3054eba | 2015-02-24 14:36:18 -0800 | [diff] [blame] | 38 | ```sh |
| 39 | $ ./greeter_server |
| 40 | ``` |
Yang Gao | ecee424 | 2015-02-24 14:46:53 -0800 | [diff] [blame] | 41 | Run the client (in a different terminal): |
Yang Gao | 3054eba | 2015-02-24 14:36:18 -0800 | [diff] [blame] | 42 | ```sh |
| 43 | $ ./greeter_client |
| 44 | ``` |
Yang Gao | ecee424 | 2015-02-24 14:46:53 -0800 | [diff] [blame] | 45 | If things go smoothly, you will see the "Greeter received: Hello world" in the client side output. |
LisaFC | d1e11e7 | 2015-02-23 18:16:08 +0000 | [diff] [blame] | 46 | |
| 47 | ## Tutorial |
| 48 | |
yang-g | b00a3f6 | 2015-08-28 14:19:37 -0700 | [diff] [blame] | 49 | You can find a more detailed tutorial in [gRPC Basics: C++](cpptutorial.md) |