Merge pull request #3184 from murgatroid99/node_examples_update

Fixed routeguide namespace, updated README to match other changes
pull/3224/head
Tim Emiola 10 years ago
commit a4cfb63b06
  1. 27
      examples/node/route_guide/README.md
  2. 4
      examples/node/route_guide/route_guide.proto
  3. 6
      examples/node/route_guide/route_guide_client.js
  4. 4
      examples/node/route_guide/route_guide_server.js

@ -96,10 +96,10 @@ To load a `.proto` file, simply `require` the gRPC library, then use its `load()
var grpc = require('grpc');
var protoDescriptor = grpc.load(__dirname + '/route_guide.proto');
// The protoDescriptor object has the full package hierarchy
var example = protoDescriptor.examples;
var example = protoDescriptor.routeguide;
```
Once you've done this, the stub constructor is in the `examples` namespace (`protoDescriptor.examples.RouteGuide`) and the service descriptor (which is used to create a server) is a property of the stub (`protoDescriptor.examples.RouteGuide.service`);
Once you've done this, the stub constructor is in the `routeguide` namespace (`protoDescriptor.routeguide.RouteGuide`) and the service descriptor (which is used to create a server) is a property of the stub (`protoDescriptor.routeguide.RouteGuide.service`);
<a name="server"></a>
## Creating the server
@ -117,7 +117,7 @@ You can find our example `RouteGuide` server in [route_guide_server.js](route_gu
As you can see, our server has a `Server` constructor generated from the `RouteGuide.service` descriptor object
```node
var Server = grpc.buildServer([examples.RouteGuide.service]);
var Server = grpc.buildServer([routeguide.RouteGuide.service]);
```
In this case we're implementing the *asynchronous* version of `RouteGuide`, which provides our default gRPC server behaviour.
@ -219,18 +219,18 @@ Once we've implemented all our methods, we also need to start up a gRPC server s
```node
function getServer() {
return new Server({
'examples.RouteGuide' : {
getFeature: getFeature,
listFeatures: listFeatures,
recordRoute: recordRoute,
routeChat: routeChat
}
var server = new grpc.Server();
server.addProtoService(routeguide.RouteGuide.service, {
getFeature: getFeature,
listFeatures: listFeatures,
recordRoute: recordRoute,
routeChat: routeChat
});
return server;
}
var routeServer = getServer();
routeServer.bind('0.0.0.0:50051');
routeServer.listen();
routeServer.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
routeServer.start();
```
As you can see, we build and start our server with the following steps:
@ -251,7 +251,8 @@ In this section, we'll look at creating a Node.js client for our `RouteGuide` se
To call service methods, we first need to create a *stub*. To do this, we just need to call the RouteGuide stub constructor, specifying the server address and port.
```node
new example.RouteGuide('localhost:50051');
var client = new routeguide.RouteGuide('localhost:50051',
grpc.Credentials.createInsecure());
```
### Calling service methods

@ -29,9 +29,9 @@
syntax = "proto3";
option java_package = "io.grpc.examples";
option java_package = "io.grpc.routeguide";
package examples;
package routeguide;
// Interface exported by the server.
service RouteGuide {

@ -33,9 +33,9 @@ var parseArgs = require('minimist');
var path = require('path');
var _ = require('underscore');
var grpc = require('grpc');
var examples = grpc.load(__dirname + '/route_guide.proto').examples;
var client = new examples.RouteGuide('localhost:50051',
grpc.Credentials.createInsecure());
var routeguide = grpc.load(__dirname + '/route_guide.proto').routeguide;
var client = new routeguide.RouteGuide('localhost:50051',
grpc.Credentials.createInsecure());
var COORD_FACTOR = 1e7;

@ -32,7 +32,7 @@ var parseArgs = require('minimist');
var path = require('path');
var _ = require('underscore');
var grpc = require('grpc');
var examples = grpc.load(__dirname + '/route_guide.proto').examples;
var routeguide = grpc.load(__dirname + '/route_guide.proto').routeguide;
var COORD_FACTOR = 1e7;
@ -221,7 +221,7 @@ function routeChat(call) {
*/
function getServer() {
var server = new grpc.Server();
server.addProtoService(examples.RouteGuide.service, {
server.addProtoService(routeguide.RouteGuide.service, {
getFeature: getFeature,
listFeatures: listFeatures,
recordRoute: recordRoute,

Loading…
Cancel
Save