murgatroid99 | 5de22f5 | 2015-06-12 11:21:55 -0700 | [diff] [blame] | 1 | #gRPC in 3 minutes (Objective-C) |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 2 | |
| 3 | ## Installation |
| 4 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame] | 5 | To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well |
| 6 | as the relevant tools to generate the client library code (and a server in another language, for |
| 7 | testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc). |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 8 | |
murgatroid99 | 5de22f5 | 2015-06-12 11:21:55 -0700 | [diff] [blame] | 9 | ## Hello Objective-C gRPC! |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 10 | |
Stanley Cheung | 56debcb | 2015-08-31 12:17:34 -0700 | [diff] [blame] | 11 | Here's how to build and run the Objective-C implementation of the [Hello World](../../protos/helloworld.proto) |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 12 | example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples). |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 13 | |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 14 | The example code for this and our other examples lives in the `examples` directory. Clone |
Jorge Canizales | 1f5d62b | 2015-10-27 10:50:03 -0700 | [diff] [blame] | 15 | this repository to your local machine by running the following commands: |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 16 | |
| 17 | |
| 18 | ```sh |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 19 | $ git clone https://github.com/grpc/grpc.git |
Jorge Canizales | 1f5d62b | 2015-10-27 10:50:03 -0700 | [diff] [blame] | 20 | $ cd grpc |
| 21 | $ git submodule update --init |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 22 | ``` |
| 23 | |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 24 | Change your current directory to `examples/objective-c/helloworld` |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 25 | |
| 26 | ```sh |
Stanley Cheung | 0a26821 | 2015-08-27 14:38:38 -0700 | [diff] [blame] | 27 | $ cd examples/objective-c/helloworld |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 28 | ``` |
| 29 | |
| 30 | ### Try it! |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame] | 31 | To try the sample app, we need a gRPC server running locally. Let's compile and run, for example, |
| 32 | the C++ server in this repository: |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 33 | |
| 34 | ```shell |
| 35 | $ pushd ../../cpp/helloworld |
| 36 | $ make |
| 37 | $ ./greeter_server & |
| 38 | $ popd |
| 39 | ``` |
| 40 | |
| 41 | Now have Cocoapods generate and install the client library for our .proto files: |
| 42 | |
| 43 | ```shell |
| 44 | $ pod install |
| 45 | ``` |
| 46 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame] | 47 | (This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet |
| 48 | on your computer's cache.) |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 49 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame] | 50 | Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling |
| 51 | code in `main.m` and see the results in XCode's log console. |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 52 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame] | 53 | The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server |
| 54 | responds with a `HLWHelloResponse`, which contains a string that is then output to the log. |
murgatroid99 | 5de22f5 | 2015-06-12 11:21:55 -0700 | [diff] [blame] | 55 | |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 56 | ## Tutorial |
| 57 | |
Jorge Canizales | 1f5d62b | 2015-10-27 10:50:03 -0700 | [diff] [blame] | 58 | You can find a more detailed tutorial in [gRPC Basics: Objective-C](http://www.grpc.io/docs/tutorials/basic/objective-c.html). |