Merge pull request #65 from yang-g/rgreadme

Update README
pull/3109/head
Abhishek Kumar 10 years ago
commit 40508e380b
  1. 30
      cpp/cpptutorial.md
  2. 5
      cpp/route_guide/route_guide_server.cc

@ -20,7 +20,7 @@ With gRPC we can define our service once in a .proto file and implement clients
## Example code and setup ## Example code and setup
The example code for our tutorial is in [grpc/grpc-common/cpp/route_guide](https://github.com/grpc/grpc-common/cpp/route_guide). To download the example, clone the `grpc-common` repository by running the following command: The example code for our tutorial is in [grpc/grpc-common/cpp/route_guide](https://github.com/grpc/grpc-common/tree/master/cpp/route_guide). To download the example, clone the `grpc-common` repository by running the following command:
```shell ```shell
$ git clone https://github.com/google/grpc-common.git $ git clone https://github.com/google/grpc-common.git
``` ```
@ -101,7 +101,9 @@ $ make route_guide.pb.cc
which actually runs: which actually runs:
[actual command] ```shell
$ protoc -I ../../protos --cpp_out=. --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto
```
Running this command generates the following files: Running this command generates the following files:
- `route_guide.pb.h`, the header which declares your generated classes - `route_guide.pb.h`, the header which declares your generated classes
@ -123,7 +125,7 @@ There are two parts to making our `RouteGuide` service do its job:
- Implementing the service interface generated from our service definition: doing the actual "work" of our service. - Implementing the service interface generated from our service definition: doing the actual "work" of our service.
- Running a gRPC server to listen for requests from clients and return the service responses. - Running a gRPC server to listen for requests from clients and return the service responses.
You can find our example `RouteGuide` server in [grpc-common/cpp/route_guide/route_guide_server.cc]((https://github.com/grpc/grpc-common/blob/master/cpp/route_guide/route_guide_server.cc). Let's take a closer look at how it works. You can find our example `RouteGuide` server in [grpc-common/cpp/route_guide/route_guide_server.cc](https://github.com/grpc/grpc-common/blob/master/cpp/route_guide/route_guide_server.cc). Let's take a closer look at how it works.
### Implementing RouteGuide ### Implementing RouteGuide
@ -218,9 +220,7 @@ void RunServer(const std::string& db_path) {
builder.RegisterService(&service); builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart()); std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl; std::cout << "Server listening on " << server_address << std::endl;
while (true) { server->Wait();
std::this_thread::sleep_for(std::chrono::seconds(5));
}
} }
``` ```
As you can see, we build and start our server using a `ServerBuilder`. To do this, we: As you can see, we build and start our server using a `ServerBuilder`. To do this, we:
@ -230,8 +230,7 @@ As you can see, we build and start our server using a `ServerBuilder`. To do thi
3. Specify the address and port we want to use to listen for client requests using the builder's `AddPort()` method. 3. Specify the address and port we want to use to listen for client requests using the builder's `AddPort()` method.
4. Register our service implementation with the builder. 4. Register our service implementation with the builder.
5. Call `BuildAndStart()` on the builder to create and start an RPC server for our service. 5. Call `BuildAndStart()` on the builder to create and start an RPC server for our service.
5. Call `Wait()` on the server to do a blocking wait until process is killed or `Shutdown()` is called.
_[is there no equivalent of the Stubby4 wait() method, ie do you have to do the while(true) loop to keep the server running?]_
<a name="client"></a> <a name="client"></a>
## Creating the client ## Creating the client
@ -351,7 +350,16 @@ The syntax for reading and writing here is exactly the same as for our client-st
## Try it out! ## Try it out!
_[need build and run instructions here]_ Build client and server:
```shell
$ make
```
Run the server, which will listen on port 50051:
```shell
$ ./route_guide_server
```
Run the client (in a different terminal):
```shell
$ ./route_guide_client
```

@ -37,7 +37,6 @@
#include <iostream> #include <iostream>
#include <memory> #include <memory>
#include <string> #include <string>
#include <thread>
#include <grpc/grpc.h> #include <grpc/grpc.h>
#include <grpc++/server.h> #include <grpc++/server.h>
@ -191,9 +190,7 @@ void RunServer(const std::string& db_path) {
builder.RegisterService(&service); builder.RegisterService(&service);
std::unique_ptr<Server> server(builder.BuildAndStart()); std::unique_ptr<Server> server(builder.BuildAndStart());
std::cout << "Server listening on " << server_address << std::endl; std::cout << "Server listening on " << server_address << std::endl;
while (true) { server->Wait();
std::this_thread::sleep_for(std::chrono::seconds(5));
}
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {

Loading…
Cancel
Save