aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/cpp/README.md31
-rw-r--r--examples/cpp/cpptutorial.md337
-rw-r--r--examples/csharp/helloworld-from-cli/Greeter/Helloworld.cs259
-rw-r--r--examples/csharp/helloworld-from-cli/Greeter/HelloworldGrpc.cs143
-rw-r--r--examples/csharp/helloworld-from-cli/Greeter/project.json22
-rw-r--r--examples/csharp/helloworld-from-cli/GreeterClient/Program.cs53
-rw-r--r--examples/csharp/helloworld-from-cli/GreeterClient/project.json26
-rw-r--r--examples/csharp/helloworld-from-cli/GreeterServer/Program.cs66
-rw-r--r--examples/csharp/helloworld-from-cli/GreeterServer/project.json26
-rw-r--r--examples/csharp/helloworld-from-cli/README.md59
-rw-r--r--examples/node/package.json4
-rw-r--r--examples/php/route_guide/README.md2
-rw-r--r--examples/python/route_guide/route_guide_server.py2
13 files changed, 901 insertions, 129 deletions
diff --git a/examples/cpp/README.md b/examples/cpp/README.md
index 3fa7ad4c78..783935cd53 100644
--- a/examples/cpp/README.md
+++ b/examples/cpp/README.md
@@ -2,26 +2,14 @@
## Installation
-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`.
+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`.
## Hello C++ gRPC!
-Here's how to build and run the C++ implementation of the [Hello World](../protos/helloworld.proto) example used in [Getting started](..).
-
-The example code for this and our other examples lives in the `examples`
-directory. Clone this repository to your local machine by running the
-following command:
-
-
-```sh
-$ git clone -b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc
-```
-
-Change your current directory to examples/cpp/helloworld
-
-```sh
-$ cd examples/cpp/helloworld/
-```
+Here's how to build and run the C++ implementation of the [Hello
+World](../protos/helloworld.proto) example used in [Getting started](..).
### Client and server implementations
@@ -31,18 +19,25 @@ The server implementation is at [greeter_server.cc](helloworld/greeter_server.cc
### Try it!
Build client and server:
+
```sh
$ make
```
+
Run the server, which will listen on port 50051:
+
```sh
$ ./greeter_server
```
+
Run the client (in a different terminal):
+
```sh
$ ./greeter_client
```
-If things go smoothly, you will see the "Greeter received: Hello world" in the client side output.
+
+If things go smoothly, you will see the "Greeter received: Hello world" in the
+client side output.
## Tutorial
diff --git a/examples/cpp/cpptutorial.md b/examples/cpp/cpptutorial.md
index 80fef07192..ae84aba916 100644
--- a/examples/cpp/cpptutorial.md
+++ b/examples/cpp/cpptutorial.md
@@ -1,58 +1,77 @@
#gRPC Basics: C++
-This tutorial provides a basic C++ programmer's introduction to working with gRPC. By walking through this example you'll learn how to:
+This tutorial provides a basic C++ programmer's introduction to working with
+gRPC. By walking through this example you'll learn how to:
-- Define a service in a .proto file.
+- Define a service in a `.proto` file.
- Generate server and client code using the protocol buffer compiler.
- Use the C++ gRPC API to write a simple client and server for your service.
-It assumes that you have read the [Getting started](..) guide and are familiar with [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language, which is currently in alpha release: you can find out more in the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and see the [release notes](https://github.com/google/protobuf/releases) for the new version in the protocol buffers Github repository.
-
-This isn't a comprehensive guide to using gRPC in C++: more reference documentation is coming soon.
+It assumes that you are familiar with
+[protocol buffers](https://developers.google.com/protocol-buffers/docs/overview).
+Note that the example in this tutorial uses the proto3 version of the protocol
+buffers language, which is currently in alpha release: you can find out more in
+the [proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3)
+and see the [release notes](https://github.com/google/protobuf/releases) for the
+new version in the protocol buffers Github repository.
## Why use gRPC?
-Our example is a simple route mapping application that lets clients get information about features on their route, create a summary of their route, and exchange route information such as traffic updates with the server and other clients.
+Our example is a simple route mapping application that lets clients get
+information about features on their route, create a summary of their route, and
+exchange route information such as traffic updates with the server and other
+clients.
-With gRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC's supported languages, which in turn can be run in environments ranging from servers inside Google to your own tablet - all the complexity of communication between different languages and environments is handled for you by gRPC. We also get all the advantages of working with protocol buffers, including efficient serialization, a simple IDL, and easy interface updating.
+With gRPC we can define our service once in a `.proto` file and implement clients
+and servers in any of gRPC's supported languages, which in turn can be run in
+environments ranging from servers inside Google to your own tablet - all the
+complexity of communication between different languages and environments is
+handled for you by gRPC. We also get all the advantages of working with protocol
+buffers, including efficient serialization, a simple IDL, and easy interface
+updating.
## Example code and setup
-The example code for our tutorial is in [examples/cpp/route_guide](route_guide). To download the example, clone this repository by running the following command:
-```shell
-$ git clone -b $(curl -L http://grpc.io/release) https://github.com/grpc/grpc
-```
-
-Then change your current directory to `examples/cpp/route_guide`:
-```shell
-$ cd examples/cpp/route_guide
-```
-
-You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [gRPC in 3 minutes](README.md).
-
+The example code for our tutorial is in [examples/cpp/route_guide](route_guide).
+You also should have the relevant tools installed to generate the server and
+client interface code - if you don't already, follow the setup instructions in
+[INSTALL.md](../../INSTALL.md).
## Defining the service
-Our first step (as you'll know from [Getting started](..) is to define the gRPC *service* and the method *request* and *response* types using [protocol buffers] (https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](../protos/route_guide.proto).
+Our first step is to define the gRPC *service* and the method *request* and
+*response* types using
+[protocol buffers](https://developers.google.com/protocol-buffers/docs/overview).
+You can see the complete `.proto` file in
+[`examples/protos/route_guide.proto`](../protos/route_guide.proto).
-To define a service, you specify a named `service` in your .proto file:
+To define a service, you specify a named `service` in your `.proto` file:
-```
+```protobuf
service RouteGuide {
...
}
```
-Then you define `rpc` methods inside your service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service:
+Then you define `rpc` methods inside your service definition, specifying their
+request and response types. gRPC lets you define four kinds of service method,
+all of which are used in the `RouteGuide` service:
-- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call.
-```
+- A *simple RPC* where the client sends a request to the server using the stub
+ and waits for a response to come back, just like a normal function call.
+
+```protobuf
// Obtains the feature at a given position.
rpc GetFeature(Point) returns (Feature) {}
```
-- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type.
-```
+- A *server-side streaming RPC* where the client sends a request to the server
+ and gets a stream to read a sequence of messages back. The client reads from
+ the returned stream until there are no more messages. As you can see in our
+ example, you specify a server-side streaming method by placing the `stream`
+ keyword before the *response* type.
+
+```protobuf
// Obtains the Features available within the given Rectangle. Results are
// streamed rather than returned at once (e.g. in a response message with a
// repeated field), as the rectangle may cover a large area and contain a
@@ -60,22 +79,38 @@ Then you define `rpc` methods inside your service definition, specifying their r
rpc ListFeatures(Rectangle) returns (stream Feature) {}
```
-- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type.
-```
+- A *client-side streaming RPC* where the client writes a sequence of messages
+ and sends them to the server, again using a provided stream. Once the client
+ has finished writing the messages, it waits for the server to read them all
+ and return its response. You specify a client-side streaming method by placing
+ the `stream` keyword before the *request* type.
+
+```protobuf
// Accepts a stream of Points on a route being traversed, returning a
// RouteSummary when traversal is completed.
rpc RecordRoute(stream Point) returns (RouteSummary) {}
```
-- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response.
-```
+- A *bidirectional streaming RPC* where both sides send a sequence of messages
+ using a read-write stream. The two streams operate independently, so clients
+ and servers can read and write in whatever order they like: for example, the
+ server could wait to receive all the client messages before writing its
+ responses, or it could alternately read a message then write a message, or
+ some other combination of reads and writes. The order of messages in each
+ stream is preserved. You specify this type of method by placing the `stream`
+ keyword before both the request and the response.
+
+```protobuf
// Accepts a stream of RouteNotes sent while a route is being traversed,
// while receiving other RouteNotes (e.g. from other users).
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
```
-Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type:
-```
+Our `.proto` file also contains protocol buffer message type definitions for all
+the request and response types used in our service methods - for example, here's
+the `Point` message type:
+
+```protobuf
// Points are represented as latitude-longitude pairs in the E7 representation
// (degrees multiplied by 10**7 and rounded to the nearest integer).
// Latitudes should be in the range +/- 90 degrees and longitude should be in
@@ -86,12 +121,16 @@ message Point {
}
```
-
## Generating client and server code
-Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with a special gRPC C++ plugin.
+Next we need to generate the gRPC client and server interfaces from our `.proto`
+service definition. We do this using the protocol buffer compiler `protoc` with
+a special gRPC C++ plugin.
-For simplicity, we've provided a [makefile](route_guide/Makefile) that runs `protoc` for you with the appropriate plugin, input, and output (if you want to run this yourself, make sure you've installed protoc and followed the gRPC code [installation instructions](../../INSTALL.md) first):
+For simplicity, we've provided a [Makefile](route_guide/Makefile) that runs
+`protoc` for you with the appropriate plugin, input, and output (if you want to
+run this yourself, make sure you've installed protoc and followed the gRPC code
+[installation instructions](../../INSTALL.md) first):
```shell
$ make route_guide.grpc.pb.cc route_guide.pb.cc
@@ -107,39 +146,58 @@ $ protoc -I ../../protos --cpp_out=. ../../protos/route_guide.proto
Running this command generates the following files in your current directory:
- `route_guide.pb.h`, the header which declares your generated message classes
- `route_guide.pb.cc`, which contains the implementation of your message classes
-- `route_guide.grpc.pb.h`, the header which declares your generated service classes
-- `route_guide.grpc.pb.cc`, which contains the implementation of your service classes
+- `route_guide.grpc.pb.h`, the header which declares your generated service
+ classes
+- `route_guide.grpc.pb.cc`, which contains the implementation of your service
+ classes
These contain:
-- All the protocol buffer code to populate, serialize, and retrieve our request and response message types
+- All the protocol buffer code to populate, serialize, and retrieve our request
+ and response message types
- A class called `RouteGuide` that contains
- - a remote interface type (or *stub*) for clients to call with the methods defined in the `RouteGuide` service.
- - two abstract interfaces for servers to implement, also with the methods defined in the `RouteGuide` service.
+ - a remote interface type (or *stub*) for clients to call with the methods
+ defined in the `RouteGuide` service.
+ - two abstract interfaces for servers to implement, also with the methods
+ defined in the `RouteGuide` service.
<a name="server"></a>
## Creating the server
-First let's look at how we create a `RouteGuide` server. If you're only interested in creating gRPC clients, you can skip this section and go straight to [Creating the client](#client) (though you might find it interesting anyway!).
+First let's look at how we create a `RouteGuide` server. If you're only
+interested in creating gRPC clients, you can skip this section and go straight
+to [Creating the client](#client) (though you might find it interesting
+anyway!).
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.
-- Running a gRPC server to listen for requests from clients and return the service responses.
+- 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.
-You can find our example `RouteGuide` server in [route_guide/route_guide_server.cc](route_guide/route_guide_server.cc). Let's take a closer look at how it works.
+You can find our example `RouteGuide` server in
+[route_guide/route_guide_server.cc](route_guide/route_guide_server.cc). Let's
+take a closer look at how it works.
### Implementing RouteGuide
-As you can see, our server has a `RouteGuideImpl` class that implements the generated `RouteGuide::Service` interface:
+As you can see, our server has a `RouteGuideImpl` class that implements the
+generated `RouteGuide::Service` interface:
```cpp
class RouteGuideImpl final : public RouteGuide::Service {
...
}
```
-In this case we're implementing the *synchronous* version of `RouteGuide`, which provides our default gRPC server behaviour. It's also possible to implement an asynchronous interface, `RouteGuide::AsyncService`, which allows you to further customize your server's threading behaviour, though we won't look at this in this tutorial.
+In this case we're implementing the *synchronous* version of `RouteGuide`, which
+provides our default gRPC server behaviour. It's also possible to implement an
+asynchronous interface, `RouteGuide::AsyncService`, which allows you to further
+customize your server's threading behaviour, though we won't look at this in
+this tutorial.
-`RouteGuideImpl` implements all our service methods. Let's look at the simplest type first, `GetFeature`, which just gets a `Point` from the client and returns the corresponding feature information from its database in a `Feature`.
+`RouteGuideImpl` implements all our service methods. Let's look at the simplest
+type first, `GetFeature`, which just gets a `Point` from the client and returns
+the corresponding feature information from its database in a `Feature`.
```cpp
Status GetFeature(ServerContext* context, const Point* point,
@@ -150,34 +208,52 @@ In this case we're implementing the *synchronous* version of `RouteGuide`, which
}
```
-The method is passed a context object for the RPC, the client's `Point` protocol buffer request, and a `Feature` protocol buffer to fill in with the response information. In the method we populate the `Feature` with the appropriate information, and then `return` with an `OK` status to tell gRPC that we've finished dealing with the RPC and that the `Feature` can be returned to the client.
+The method is passed a context object for the RPC, the client's `Point` protocol
+buffer request, and a `Feature` protocol buffer to fill in with the response
+information. In the method we populate the `Feature` with the appropriate
+information, and then `return` with an `OK` status to tell gRPC that we've
+finished dealing with the RPC and that the `Feature` can be returned to the
+client.
-Now let's look at something a bit more complicated - a streaming RPC. `ListFeatures` is a server-side streaming RPC, so we need to send back multiple `Feature`s to our client.
+Now let's look at something a bit more complicated - a streaming RPC.
+`ListFeatures` is a server-side streaming RPC, so we need to send back multiple
+`Feature`s to our client.
```cpp
- Status ListFeatures(ServerContext* context, const Rectangle* rectangle,
- ServerWriter<Feature>* writer) override {
- auto lo = rectangle->lo();
- auto hi = rectangle->hi();
- long left = std::min(lo.longitude(), hi.longitude());
- long right = std::max(lo.longitude(), hi.longitude());
- long top = std::max(lo.latitude(), hi.latitude());
- long bottom = std::min(lo.latitude(), hi.latitude());
- for (const Feature& f : feature_list_) {
- if (f.location().longitude() >= left &&
- f.location().longitude() <= right &&
- f.location().latitude() >= bottom &&
- f.location().latitude() <= top) {
- writer->Write(f);
- }
+Status ListFeatures(ServerContext* context, const Rectangle* rectangle,
+ ServerWriter<Feature>* writer) override {
+ auto lo = rectangle->lo();
+ auto hi = rectangle->hi();
+ long left = std::min(lo.longitude(), hi.longitude());
+ long right = std::max(lo.longitude(), hi.longitude());
+ long top = std::max(lo.latitude(), hi.latitude());
+ long bottom = std::min(lo.latitude(), hi.latitude());
+ for (const Feature& f : feature_list_) {
+ if (f.location().longitude() >= left &&
+ f.location().longitude() <= right &&
+ f.location().latitude() >= bottom &&
+ f.location().latitude() <= top) {
+ writer->Write(f);
}
- return Status::OK;
}
+ return Status::OK;
+}
```
-As you can see, instead of getting simple request and response objects in our method parameters, this time we get a request object (the `Rectangle` in which our client wants to find `Feature`s) and a special `ServerWriter` object. In the method, we populate as many `Feature` objects as we need to return, writing them to the `ServerWriter` using its `Write()` method. Finally, as in our simple RPC, we `return Status::OK` to tell gRPC that we've finished writing responses.
+As you can see, instead of getting simple request and response objects in our
+method parameters, this time we get a request object (the `Rectangle` in which
+our client wants to find `Feature`s) and a special `ServerWriter` object. In the
+method, we populate as many `Feature` objects as we need to return, writing them
+to the `ServerWriter` using its `Write()` method. Finally, as in our simple RPC,
+we `return Status::OK` to tell gRPC that we've finished writing responses.
-If you look at the client-side streaming method `RecordRoute` you'll see it's quite similar, except this time we get a `ServerReader` instead of a request object and a single response. We use the `ServerReader`s `Read()` method to repeatedly read in our client's requests to a request object (in this case a `Point`) until there are no more messages: the server needs to check the return value of `Read()` after each call. If `true`, the stream is still good and it can continue reading; if `false` the message stream has ended.
+If you look at the client-side streaming method `RecordRoute` you'll see it's
+quite similar, except this time we get a `ServerReader` instead of a request
+object and a single response. We use the `ServerReader`s `Read()` method to
+repeatedly read in our client's requests to a request object (in this case a
+`Point`) until there are no more messages: the server needs to check the return
+value of `Read()` after each call. If `true`, the stream is still good and it
+can continue reading; if `false` the message stream has ended.
```cpp
while (stream->Read(&point)) {
@@ -205,11 +281,18 @@ Finally, let's look at our bidirectional streaming RPC `RouteChat()`.
}
```
-This time we get a `ServerReaderWriter` that can be used to read *and* write messages. The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
+This time we get a `ServerReaderWriter` that can be used to read *and* write
+messages. The syntax for reading and writing here is exactly the same as for our
+client-streaming and server-streaming methods. Although each side will always
+get the other's messages in the order they were written, both the client and
+server can read and write in any order — the streams operate completely
+independently.
### Starting the server
-Once we've implemented all our methods, we also need to start up a gRPC server so that clients can actually use our service. The following snippet shows how we do this for our `RouteGuide` service:
+Once we've implemented all our methods, we also need to start up a gRPC server
+so that clients can actually use our service. The following snippet shows how we
+do this for our `RouteGuide` service:
```cpp
void RunServer(const std::string& db_path) {
@@ -227,44 +310,55 @@ void RunServer(const std::string& db_path) {
As you can see, we build and start our server using a `ServerBuilder`. To do this, we:
1. Create an instance of our service implementation class `RouteGuideImpl`.
-2. Create an instance of the factory `ServerBuilder` class.
-3. Specify the address and port we want to use to listen for client requests using the builder's `AddListeningPort()` method.
-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 `Wait()` on the server to do a blocking wait until process is killed or `Shutdown()` is called.
+1. Create an instance of the factory `ServerBuilder` class.
+1. Specify the address and port we want to use to listen for client requests
+ using the builder's `AddListeningPort()` method.
+1. Register our service implementation with the builder.
+1. Call `BuildAndStart()` on the builder to create and start an RPC server for
+ our service.
+1. Call `Wait()` on the server to do a blocking wait until process is killed or
+ `Shutdown()` is called.
<a name="client"></a>
## Creating the client
-In this section, we'll look at creating a C++ client for our `RouteGuide` service. You can see our complete example client code in [route_guide/route_guide_client.cc](route_guide/route_guide_client.cc).
+In this section, we'll look at creating a C++ client for our `RouteGuide`
+service. You can see our complete example client code in
+[route_guide/route_guide_client.cc](route_guide/route_guide_client.cc).
### Creating a stub
To call service methods, we first need to create a *stub*.
-First we need to create a gRPC *channel* for our stub, specifying the server address and port we want to connect to without SSL:
+First we need to create a gRPC *channel* for our stub, specifying the server
+address and port we want to connect to without SSL:
```cpp
grpc::CreateChannel("localhost:50051", grpc::InsecureChannelCredentials());
```
-Now we can use the channel to create our stub using the `NewStub` method provided in the `RouteGuide` class we generated from our .proto.
+Now we can use the channel to create our stub using the `NewStub` method
+provided in the `RouteGuide` class we generated from our `.proto`.
```cpp
- public:
- RouteGuideClient(std::shared_ptr<Channel> channel, const std::string& db)
- : stub_(RouteGuide::NewStub(channel)) {
- ...
- }
+public:
+ RouteGuideClient(std::shared_ptr<Channel> channel, const std::string& db)
+ : stub_(RouteGuide::NewStub(channel)) {
+ ...
+ }
```
### Calling service methods
-Now let's look at how we call our service methods. Note that in this tutorial we're calling the *blocking/synchronous* versions of each method: this means that the RPC call waits for the server to respond, and will either return a response or raise an exception.
+Now let's look at how we call our service methods. Note that in this tutorial
+we're calling the *blocking/synchronous* versions of each method: this means
+that the RPC call waits for the server to respond, and will either return a
+response or raise an exception.
#### Simple RPC
-Calling the simple RPC `GetFeature` is nearly as straightforward as calling a local method.
+Calling the simple RPC `GetFeature` is nearly as straightforward as calling a
+local method.
```cpp
Point point;
@@ -281,33 +375,53 @@ Calling the simple RPC `GetFeature` is nearly as straightforward as calling a lo
}
```
-As you can see, we create and populate a request protocol buffer object (in our case `Point`), and create a response protocol buffer object for the server to fill in. We also create a `ClientContext` object for our call - you can optionally set RPC configuration values on this object, such as deadlines, though for now we'll use the default settings. Note that you cannot reuse this object between calls. Finally, we call the method on the stub, passing it the context, request, and response. If the method returns `OK`, then we can read the response information from the server from our response object.
+As you can see, we create and populate a request protocol buffer object (in our
+case `Point`), and create a response protocol buffer object for the server to
+fill in. We also create a `ClientContext` object for our call - you can
+optionally set RPC configuration values on this object, such as deadlines,
+though for now we'll use the default settings. Note that you cannot reuse this
+object between calls. Finally, we call the method on the stub, passing it the
+context, request, and response. If the method returns `OK`, then we can read the
+response information from the server from our response object.
```cpp
- std::cout << "Found feature called " << feature->name() << " at "
- << feature->location().latitude()/kCoordFactor_ << ", "
- << feature->location().longitude()/kCoordFactor_ << std::endl;
+std::cout << "Found feature called " << feature->name() << " at "
+ << feature->location().latitude()/kCoordFactor_ << ", "
+ << feature->location().longitude()/kCoordFactor_ << std::endl;
```
#### Streaming RPCs
-Now let's look at our streaming methods. If you've already read [Creating the server](#server) some of this may look very familiar - streaming RPCs are implemented in a similar way on both sides. Here's where we call the server-side streaming method `ListFeatures`, which returns a stream of geographical `Feature`s:
+Now let's look at our streaming methods. If you've already read [Creating the
+server](#server) some of this may look very familiar - streaming RPCs are
+implemented in a similar way on both sides. Here's where we call the server-side
+streaming method `ListFeatures`, which returns a stream of geographical
+`Feature`s:
```cpp
- std::unique_ptr<ClientReader<Feature> > reader(
- stub_->ListFeatures(&context, rect));
- while (reader->Read(&feature)) {
- std::cout << "Found feature called "
- << feature.name() << " at "
- << feature.location().latitude()/kCoordFactor_ << ", "
- << feature.location().longitude()/kCoordFactor_ << std::endl;
- }
- Status status = reader->Finish();
+std::unique_ptr<ClientReader<Feature> > reader(
+ stub_->ListFeatures(&context, rect));
+while (reader->Read(&feature)) {
+ std::cout << "Found feature called "
+ << feature.name() << " at "
+ << feature.location().latitude()/kCoordFactor_ << ", "
+ << feature.location().longitude()/kCoordFactor_ << std::endl;
+}
+Status status = reader->Finish();
```
-Instead of passing the method a context, request, and response, we pass it a context and request and get a `ClientReader` object back. The client can use the `ClientReader` to read the server's responses. We use the `ClientReader`s `Read()` method to repeatedly read in the server's responses to a response protocol buffer object (in this case a `Feature`) until there are no more messages: the client needs to check the return value of `Read()` after each call. If `true`, the stream is still good and it can continue reading; if `false` the message stream has ended. Finally, we call `Finish()` on the stream to complete the call and get our RPC status.
+Instead of passing the method a context, request, and response, we pass it a
+context and request and get a `ClientReader` object back. The client can use the
+`ClientReader` to read the server's responses. We use the `ClientReader`s
+`Read()` method to repeatedly read in the server's responses to a response
+protocol buffer object (in this case a `Feature`) until there are no more
+messages: the client needs to check the return value of `Read()` after each
+call. If `true`, the stream is still good and it can continue reading; if
+`false` the message stream has ended. Finally, we call `Finish()` on the stream
+to complete the call and get our RPC status.
-The client-side streaming method `RecordRoute` is similar, except there we pass the method a context and response object and get back a `ClientWriter`.
+The client-side streaming method `RecordRoute` is similar, except there we pass
+the method a context and response object and get back a `ClientWriter`.
```cpp
std::unique_ptr<ClientWriter<Point> > writer(
@@ -337,16 +451,26 @@ The client-side streaming method `RecordRoute` is similar, except there we pass
}
```
-Once we've finished writing our client's requests to the stream using `Write()`, we need to call `WritesDone()` on the stream to let gRPC know that we've finished writing, then `Finish()` to complete the call and get our RPC status. If the status is `OK`, our response object that we initially passed to `RecordRoute()` will be populated with the server's response.
+Once we've finished writing our client's requests to the stream using `Write()`,
+we need to call `WritesDone()` on the stream to let gRPC know that we've
+finished writing, then `Finish()` to complete the call and get our RPC status.
+If the status is `OK`, our response object that we initially passed to
+`RecordRoute()` will be populated with the server's response.
-Finally, let's look at our bidirectional streaming RPC `RouteChat()`. In this case, we just pass a context to the method and get back a `ClientReaderWriter`, which we can use to both write and read messages.
+Finally, let's look at our bidirectional streaming RPC `RouteChat()`. In this
+case, we just pass a context to the method and get back a `ClientReaderWriter`,
+which we can use to both write and read messages.
```cpp
- std::shared_ptr<ClientReaderWriter<RouteNote, RouteNote> > stream(
- stub_->RouteChat(&context));
+std::shared_ptr<ClientReaderWriter<RouteNote, RouteNote> > stream(
+ stub_->RouteChat(&context));
```
-The syntax for reading and writing here is exactly the same as for our client-streaming and server-streaming methods. Although each side will always get the other's messages in the order they were written, both the client and server can read and write in any order — the streams operate completely independently.
+The syntax for reading and writing here is exactly the same as for our
+client-streaming and server-streaming methods. Although each side will always
+get the other's messages in the order they were written, both the client and
+server can read and write in any order — the streams operate completely
+independently.
## Try it out!
@@ -362,4 +486,3 @@ Run the client (in a different terminal):
```shell
$ ./route_guide_client
```
-
diff --git a/examples/csharp/helloworld-from-cli/Greeter/Helloworld.cs b/examples/csharp/helloworld-from-cli/Greeter/Helloworld.cs
new file mode 100644
index 0000000000..6477b4f35b
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/Greeter/Helloworld.cs
@@ -0,0 +1,259 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: helloworld.proto
+#pragma warning disable 1591, 0612, 3021
+#region Designer generated code
+
+using pb = global::Google.Protobuf;
+using pbc = global::Google.Protobuf.Collections;
+using pbr = global::Google.Protobuf.Reflection;
+using scg = global::System.Collections.Generic;
+namespace Helloworld {
+
+ /// <summary>Holder for reflection information generated from helloworld.proto</summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public static partial class HelloworldReflection {
+
+ #region Descriptor
+ /// <summary>File descriptor for helloworld.proto</summary>
+ public static pbr::FileDescriptor Descriptor {
+ get { return descriptor; }
+ }
+ private static pbr::FileDescriptor descriptor;
+
+ static HelloworldReflection() {
+ byte[] descriptorData = global::System.Convert.FromBase64String(
+ string.Concat(
+ "ChBoZWxsb3dvcmxkLnByb3RvEgpoZWxsb3dvcmxkIhwKDEhlbGxvUmVxdWVz",
+ "dBIMCgRuYW1lGAEgASgJIh0KCkhlbGxvUmVwbHkSDwoHbWVzc2FnZRgBIAEo",
+ "CTJJCgdHcmVldGVyEj4KCFNheUhlbGxvEhguaGVsbG93b3JsZC5IZWxsb1Jl",
+ "cXVlc3QaFi5oZWxsb3dvcmxkLkhlbGxvUmVwbHkiAEI2Chtpby5ncnBjLmV4",
+ "YW1wbGVzLmhlbGxvd29ybGRCD0hlbGxvV29ybGRQcm90b1ABogIDSExXYgZw",
+ "cm90bzM="));
+ descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
+ new pbr::FileDescriptor[] { },
+ new pbr::GeneratedClrTypeInfo(null, new pbr::GeneratedClrTypeInfo[] {
+ new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloRequest), global::Helloworld.HelloRequest.Parser, new[]{ "Name" }, null, null, null),
+ new pbr::GeneratedClrTypeInfo(typeof(global::Helloworld.HelloReply), global::Helloworld.HelloReply.Parser, new[]{ "Message" }, null, null, null)
+ }));
+ }
+ #endregion
+
+ }
+ #region Messages
+ /// <summary>
+ /// The request message containing the user's name.
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class HelloRequest : pb::IMessage<HelloRequest> {
+ private static readonly pb::MessageParser<HelloRequest> _parser = new pb::MessageParser<HelloRequest>(() => new HelloRequest());
+ public static pb::MessageParser<HelloRequest> Parser { get { return _parser; } }
+
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[0]; }
+ }
+
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ public HelloRequest() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ public HelloRequest(HelloRequest other) : this() {
+ name_ = other.name_;
+ }
+
+ public HelloRequest Clone() {
+ return new HelloRequest(this);
+ }
+
+ /// <summary>Field number for the "name" field.</summary>
+ public const int NameFieldNumber = 1;
+ private string name_ = "";
+ public string Name {
+ get { return name_; }
+ set {
+ name_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ public override bool Equals(object other) {
+ return Equals(other as HelloRequest);
+ }
+
+ public bool Equals(HelloRequest other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Name != other.Name) return false;
+ return true;
+ }
+
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Name.Length != 0) hash ^= Name.GetHashCode();
+ return hash;
+ }
+
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Name.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Name);
+ }
+ }
+
+ public int CalculateSize() {
+ int size = 0;
+ if (Name.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Name);
+ }
+ return size;
+ }
+
+ public void MergeFrom(HelloRequest other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Name.Length != 0) {
+ Name = other.Name;
+ }
+ }
+
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Name = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ /// <summary>
+ /// The response message containing the greetings
+ /// </summary>
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ public sealed partial class HelloReply : pb::IMessage<HelloReply> {
+ private static readonly pb::MessageParser<HelloReply> _parser = new pb::MessageParser<HelloReply>(() => new HelloReply());
+ public static pb::MessageParser<HelloReply> Parser { get { return _parser; } }
+
+ public static pbr::MessageDescriptor Descriptor {
+ get { return global::Helloworld.HelloworldReflection.Descriptor.MessageTypes[1]; }
+ }
+
+ pbr::MessageDescriptor pb::IMessage.Descriptor {
+ get { return Descriptor; }
+ }
+
+ public HelloReply() {
+ OnConstruction();
+ }
+
+ partial void OnConstruction();
+
+ public HelloReply(HelloReply other) : this() {
+ message_ = other.message_;
+ }
+
+ public HelloReply Clone() {
+ return new HelloReply(this);
+ }
+
+ /// <summary>Field number for the "message" field.</summary>
+ public const int MessageFieldNumber = 1;
+ private string message_ = "";
+ public string Message {
+ get { return message_; }
+ set {
+ message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
+ }
+ }
+
+ public override bool Equals(object other) {
+ return Equals(other as HelloReply);
+ }
+
+ public bool Equals(HelloReply other) {
+ if (ReferenceEquals(other, null)) {
+ return false;
+ }
+ if (ReferenceEquals(other, this)) {
+ return true;
+ }
+ if (Message != other.Message) return false;
+ return true;
+ }
+
+ public override int GetHashCode() {
+ int hash = 1;
+ if (Message.Length != 0) hash ^= Message.GetHashCode();
+ return hash;
+ }
+
+ public override string ToString() {
+ return pb::JsonFormatter.ToDiagnosticString(this);
+ }
+
+ public void WriteTo(pb::CodedOutputStream output) {
+ if (Message.Length != 0) {
+ output.WriteRawTag(10);
+ output.WriteString(Message);
+ }
+ }
+
+ public int CalculateSize() {
+ int size = 0;
+ if (Message.Length != 0) {
+ size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
+ }
+ return size;
+ }
+
+ public void MergeFrom(HelloReply other) {
+ if (other == null) {
+ return;
+ }
+ if (other.Message.Length != 0) {
+ Message = other.Message;
+ }
+ }
+
+ public void MergeFrom(pb::CodedInputStream input) {
+ uint tag;
+ while ((tag = input.ReadTag()) != 0) {
+ switch(tag) {
+ default:
+ input.SkipLastField();
+ break;
+ case 10: {
+ Message = input.ReadString();
+ break;
+ }
+ }
+ }
+ }
+
+ }
+
+ #endregion
+
+}
+
+#endregion Designer generated code
diff --git a/examples/csharp/helloworld-from-cli/Greeter/HelloworldGrpc.cs b/examples/csharp/helloworld-from-cli/Greeter/HelloworldGrpc.cs
new file mode 100644
index 0000000000..041f5a78d7
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/Greeter/HelloworldGrpc.cs
@@ -0,0 +1,143 @@
+// Generated by the protocol buffer compiler. DO NOT EDIT!
+// source: helloworld.proto
+// Original file comments:
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+#region Designer generated code
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Grpc.Core;
+
+namespace Helloworld {
+ /// <summary>
+ /// The greeting service definition.
+ /// </summary>
+ public static class Greeter
+ {
+ static readonly string __ServiceName = "helloworld.Greeter";
+
+ static readonly Marshaller<global::Helloworld.HelloRequest> __Marshaller_HelloRequest = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloRequest.Parser.ParseFrom);
+ static readonly Marshaller<global::Helloworld.HelloReply> __Marshaller_HelloReply = Marshallers.Create((arg) => global::Google.Protobuf.MessageExtensions.ToByteArray(arg), global::Helloworld.HelloReply.Parser.ParseFrom);
+
+ static readonly Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply> __Method_SayHello = new Method<global::Helloworld.HelloRequest, global::Helloworld.HelloReply>(
+ MethodType.Unary,
+ __ServiceName,
+ "SayHello",
+ __Marshaller_HelloRequest,
+ __Marshaller_HelloReply);
+
+ /// <summary>Service descriptor</summary>
+ public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
+ {
+ get { return global::Helloworld.HelloworldReflection.Descriptor.Services[0]; }
+ }
+
+ /// <summary>Base class for server-side implementations of Greeter</summary>
+ public abstract class GreeterBase
+ {
+ /// <summary>
+ /// Sends a greeting
+ /// </summary>
+ public virtual global::System.Threading.Tasks.Task<global::Helloworld.HelloReply> SayHello(global::Helloworld.HelloRequest request, ServerCallContext context)
+ {
+ throw new RpcException(new Status(StatusCode.Unimplemented, ""));
+ }
+
+ }
+
+ /// <summary>Client for Greeter</summary>
+ public class GreeterClient : ClientBase<GreeterClient>
+ {
+ /// <summary>Creates a new client for Greeter</summary>
+ /// <param name="channel">The channel to use to make remote calls.</param>
+ public GreeterClient(Channel channel) : base(channel)
+ {
+ }
+ /// <summary>Creates a new client for Greeter that uses a custom <c>CallInvoker</c>.</summary>
+ /// <param name="callInvoker">The callInvoker to use to make remote calls.</param>
+ public GreeterClient(CallInvoker callInvoker) : base(callInvoker)
+ {
+ }
+ /// <summary>Protected parameterless constructor to allow creation of test doubles.</summary>
+ protected GreeterClient() : base()
+ {
+ }
+ /// <summary>Protected constructor to allow creation of configured clients.</summary>
+ /// <param name="configuration">The client configuration.</param>
+ protected GreeterClient(ClientBaseConfiguration configuration) : base(configuration)
+ {
+ }
+
+ /// <summary>
+ /// Sends a greeting
+ /// </summary>
+ public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return SayHello(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ /// <summary>
+ /// Sends a greeting
+ /// </summary>
+ public virtual global::Helloworld.HelloReply SayHello(global::Helloworld.HelloRequest request, CallOptions options)
+ {
+ return CallInvoker.BlockingUnaryCall(__Method_SayHello, null, options, request);
+ }
+ /// <summary>
+ /// Sends a greeting
+ /// </summary>
+ public virtual AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken))
+ {
+ return SayHelloAsync(request, new CallOptions(headers, deadline, cancellationToken));
+ }
+ /// <summary>
+ /// Sends a greeting
+ /// </summary>
+ public virtual AsyncUnaryCall<global::Helloworld.HelloReply> SayHelloAsync(global::Helloworld.HelloRequest request, CallOptions options)
+ {
+ return CallInvoker.AsyncUnaryCall(__Method_SayHello, null, options, request);
+ }
+ protected override GreeterClient NewInstance(ClientBaseConfiguration configuration)
+ {
+ return new GreeterClient(configuration);
+ }
+ }
+
+ /// <summary>Creates service definition that can be registered with a server</summary>
+ public static ServerServiceDefinition BindService(GreeterBase serviceImpl)
+ {
+ return ServerServiceDefinition.CreateBuilder()
+ .AddMethod(__Method_SayHello, serviceImpl.SayHello).Build();
+ }
+
+ }
+}
+#endregion
diff --git a/examples/csharp/helloworld-from-cli/Greeter/project.json b/examples/csharp/helloworld-from-cli/Greeter/project.json
new file mode 100644
index 0000000000..8774941810
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/Greeter/project.json
@@ -0,0 +1,22 @@
+{
+ "title": "Greeter",
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable",
+ },
+ "dependencies": {
+ "Google.Protobuf": "3.0.0-beta3",
+ "Grpc": "1.0.0-pre1",
+ },
+ "frameworks": {
+ "net45": {
+ "frameworkAssemblies": {
+ "System.Runtime": "",
+ "System.IO": ""
+ },
+ "dependencies": {
+ "Microsoft.NETCore.Platforms": "1.0.1"
+ }
+ }
+ }
+}
diff --git a/examples/csharp/helloworld-from-cli/GreeterClient/Program.cs b/examples/csharp/helloworld-from-cli/GreeterClient/Program.cs
new file mode 100644
index 0000000000..444d473509
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/GreeterClient/Program.cs
@@ -0,0 +1,53 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using System;
+using Grpc.Core;
+using Helloworld;
+
+namespace GreeterClient
+{
+ class Program
+ {
+ public static void Main(string[] args)
+ {
+ Channel channel = new Channel("127.0.0.1:50051", ChannelCredentials.Insecure);
+
+ var client = new Greeter.GreeterClient(channel);
+ String user = "you";
+
+ var reply = client.SayHello(new HelloRequest { Name = user });
+ Console.WriteLine("Greeting: " + reply.Message);
+
+ channel.ShutdownAsync().Wait();
+ Console.WriteLine("Press any key to exit...");
+ Console.ReadKey();
+ }
+ }
+}
diff --git a/examples/csharp/helloworld-from-cli/GreeterClient/project.json b/examples/csharp/helloworld-from-cli/GreeterClient/project.json
new file mode 100644
index 0000000000..c2bf694cd8
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/GreeterClient/project.json
@@ -0,0 +1,26 @@
+{
+ "title": "GreeterClient",
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": "true"
+ },
+ "dependencies": {
+ "Google.Protobuf": "3.0.0-beta3",
+ "Grpc": "1.0.0-pre1",
+ "Greeter": {
+ "target": "project"
+ }
+ },
+ "frameworks": {
+ "net45": {
+ "frameworkAssemblies": {
+ "System.Runtime": "",
+ "System.IO": ""
+ },
+ "dependencies": {
+ "Microsoft.NETCore.Platforms": "1.0.1"
+ }
+ }
+ }
+}
diff --git a/examples/csharp/helloworld-from-cli/GreeterServer/Program.cs b/examples/csharp/helloworld-from-cli/GreeterServer/Program.cs
new file mode 100644
index 0000000000..fdab379e81
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/GreeterServer/Program.cs
@@ -0,0 +1,66 @@
+// Copyright 2015, Google Inc.
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using System;
+using System.Threading.Tasks;
+using Grpc.Core;
+using Helloworld;
+
+namespace GreeterServer
+{
+ class GreeterImpl : Greeter.GreeterBase
+ {
+ // Server side handler of the SayHello RPC
+ public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
+ {
+ return Task.FromResult(new HelloReply { Message = "Hello " + request.Name });
+ }
+ }
+
+ class Program
+ {
+ const int Port = 50051;
+
+ public static void Main(string[] args)
+ {
+ Server server = new Server
+ {
+ Services = { Greeter.BindService(new GreeterImpl()) },
+ Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
+ };
+ server.Start();
+
+ Console.WriteLine("Greeter server listening on port " + Port);
+ Console.WriteLine("Press any key to stop the server...");
+ Console.ReadKey();
+
+ server.ShutdownAsync().Wait();
+ }
+ }
+}
diff --git a/examples/csharp/helloworld-from-cli/GreeterServer/project.json b/examples/csharp/helloworld-from-cli/GreeterServer/project.json
new file mode 100644
index 0000000000..29a10670f4
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/GreeterServer/project.json
@@ -0,0 +1,26 @@
+{
+ "title": "GreeterServer",
+ "version": "1.0.0-*",
+ "buildOptions": {
+ "debugType": "portable",
+ "emitEntryPoint": "true"
+ },
+ "dependencies": {
+ "Google.Protobuf": "3.0.0-beta3",
+ "Grpc": "1.0.0-pre1",
+ "Greeter": {
+ "target": "project"
+ }
+ },
+ "frameworks": {
+ "net45": {
+ "frameworkAssemblies": {
+ "System.Runtime": "",
+ "System.IO": ""
+ },
+ "dependencies": {
+ "Microsoft.NETCore.Platforms": "1.0.1"
+ }
+ }
+ }
+}
diff --git a/examples/csharp/helloworld-from-cli/README.md b/examples/csharp/helloworld-from-cli/README.md
new file mode 100644
index 0000000000..4db077631d
--- /dev/null
+++ b/examples/csharp/helloworld-from-cli/README.md
@@ -0,0 +1,59 @@
+gRPC in 3 minutes (C#)
+========================
+
+BACKGROUND
+-------------
+This is a different version of the helloworld example, using the dotnet sdk
+tools to build and run.
+
+For this sample, we've already generated the server and client stubs from [helloworld.proto][].
+
+Example projects in this directory depend on the [Grpc](https://www.nuget.org/packages/Grpc/)
+and [Google.Protobuf](https://www.nuget.org/packages/Google.Protobuf/) NuGet packages
+which have been already added to the project for you.
+
+The examples in this directory target .NET 4.5 framework, as .NET Core support is
+currently experimental.
+
+PREREQUISITES
+-------------
+
+- The DotNetCore SDK cli.
+
+- The .NET 4.5 framework.
+
+Both are available to download at https://www.microsoft.com/net/download
+
+BUILD
+-------
+
+From the `examples/csharp/helloworld-from-cli` directory:
+
+- `dotnet restore`
+
+- `dotnet build **/project.json` (this will automatically download NuGet dependencies)
+
+Try it!
+-------
+
+- Run the server
+
+ ```
+ > cd GreeterServer
+ > dotnet run
+ ```
+
+- Run the client
+
+ ```
+ > cd GreeterClient
+ > dotnet run
+ ```
+
+Tutorial
+--------
+
+You can find a more detailed tutorial about Grpc in [gRPC Basics: C#][]
+
+[helloworld.proto]:../../protos/helloworld.proto
+[gRPC Basics: C#]:http://www.grpc.io/docs/tutorials/basic/csharp.html
diff --git a/examples/node/package.json b/examples/node/package.json
index 2cae031175..6317838295 100644
--- a/examples/node/package.json
+++ b/examples/node/package.json
@@ -3,8 +3,8 @@
"version": "0.1.0",
"dependencies": {
"async": "^1.5.2",
- "google-protobuf": "^3.0.0-alpha.5",
- "grpc": "^0.14.0",
+ "google-protobuf": "^3.0.0",
+ "grpc": "^1.0.0",
"lodash": "^4.6.1",
"minimist": "^1.2.0"
}
diff --git a/examples/php/route_guide/README.md b/examples/php/route_guide/README.md
index 4e74a79f13..26f1704f12 100644
--- a/examples/php/route_guide/README.md
+++ b/examples/php/route_guide/README.md
@@ -1,6 +1,6 @@
#gRPC Basics: PHP sample code
The files in this folder are the samples used in [gRPC Basics: PHP][],
-a detailed tutorial for using gRPC in Ruby.
+a detailed tutorial for using gRPC in PHP.
[gRPC Basics: PHP]:http://www.grpc.io/docs/tutorials/basic/php.html
diff --git a/examples/python/route_guide/route_guide_server.py b/examples/python/route_guide/route_guide_server.py
index 4e780a70a1..3ffe678476 100644
--- a/examples/python/route_guide/route_guide_server.py
+++ b/examples/python/route_guide/route_guide_server.py
@@ -68,7 +68,7 @@ def get_distance(start, end):
R = 6371000; # metres
return R * c;
-class RouteGuideServicer(route_guide_pb2.BetaRouteGuideServicer):
+class RouteGuideServicer(route_guide_pb2.RouteGuideServicer):
"""Provides methods that implement functionality of route guide server."""
def __init__(self):