Updated Node examples to be compatible with master

pull/3143/head
murgatroid99 10 years ago
parent cf08a881fb
commit c919228e0a
  1. 3
      examples/node/greeter_client.js
  2. 14
      examples/node/greeter_server.js
  3. 2
      examples/node/package.json
  4. 3
      examples/node/route_guide/route_guide_client.js
  5. 20
      examples/node/route_guide/route_guide_server.js

@ -37,7 +37,8 @@ var grpc = require('grpc');
var hello_proto = grpc.load(PROTO_PATH).helloworld; var hello_proto = grpc.load(PROTO_PATH).helloworld;
function main() { function main() {
var client = new hello_proto.Greeter('localhost:50051'); var client = new hello_proto.Greeter('localhost:50051',
grpc.Credentials.createInsecure());
var user; var user;
if (process.argv.length >= 3) { if (process.argv.length >= 3) {
user = process.argv[2]; user = process.argv[2];

@ -36,8 +36,6 @@ var PROTO_PATH = __dirname + '/helloworld.proto';
var grpc = require('grpc'); var grpc = require('grpc');
var hello_proto = grpc.load(PROTO_PATH).helloworld; var hello_proto = grpc.load(PROTO_PATH).helloworld;
var Server = grpc.buildServer([hello_proto.Greeter.service]);
/** /**
* Implements the SayHello RPC method. * Implements the SayHello RPC method.
*/ */
@ -50,14 +48,10 @@ function sayHello(call, callback) {
* sample server port * sample server port
*/ */
function main() { function main() {
var server = new Server({ var server = new grpc.Server();
"helloworld.Greeter": { server.addProtoService(hello_proto.Greeter.service, {sayHello: sayHello});
sayHello: sayHello server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
} server.start();
});
server.bind('0.0.0.0:50051');
server.listen();
} }
main(); main();

@ -3,7 +3,7 @@
"version": "0.5.0", "version": "0.5.0",
"dependencies": { "dependencies": {
"async": "^0.9.0", "async": "^0.9.0",
"grpc": "~0.9.0", "grpc": "~0.11.0",
"minimist": "^1.1.0", "minimist": "^1.1.0",
"underscore": "^1.8.2" "underscore": "^1.8.2"
} }

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

@ -34,8 +34,6 @@ var _ = require('underscore');
var grpc = require('grpc'); var grpc = require('grpc');
var examples = grpc.load(__dirname + '/route_guide.proto').examples; var examples = grpc.load(__dirname + '/route_guide.proto').examples;
var Server = grpc.buildServer([examples.RouteGuide.service]);
var COORD_FACTOR = 1e7; var COORD_FACTOR = 1e7;
/** /**
@ -222,27 +220,27 @@ function routeChat(call) {
* @return {Server} The new server object * @return {Server} The new server object
*/ */
function getServer() { function getServer() {
return new Server({ var server = new grpc.Server();
'examples.RouteGuide' : { server.addProtoService(examples.RouteGuide.service, {
getFeature: getFeature, getFeature: getFeature,
listFeatures: listFeatures, listFeatures: listFeatures,
recordRoute: recordRoute, recordRoute: recordRoute,
routeChat: routeChat routeChat: routeChat
}
}); });
return server;
} }
if (require.main === module) { if (require.main === module) {
// If this is run as a script, start a server on an unused port // If this is run as a script, start a server on an unused port
var routeServer = getServer(); var routeServer = getServer();
routeServer.bind('0.0.0.0:50051'); routeServer.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
var argv = parseArgs(process.argv, { var argv = parseArgs(process.argv, {
string: 'db_path' string: 'db_path'
}); });
fs.readFile(path.resolve(argv.db_path), function(err, data) { fs.readFile(path.resolve(argv.db_path), function(err, data) {
if (err) throw err; if (err) throw err;
feature_list = JSON.parse(data); feature_list = JSON.parse(data);
routeServer.listen(); routeServer.start();
}); });
} }

Loading…
Cancel
Save