aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/node/greeter_server.js
diff options
context:
space:
mode:
authorGravatar Julien Boeuf <jboeuf@google.com>2015-08-27 16:07:46 -0700
committerGravatar Julien Boeuf <jboeuf@google.com>2015-08-27 16:07:46 -0700
commit459faf3821b74329f5f1debdba21abe03e3a6e74 (patch)
tree2046a5d7f4f119f0770154393c4308394f26f19b /examples/node/greeter_server.js
parent35b559f6f7e4e6410613632bbfe3f2ab84073feb (diff)
parent1029e7049cea55a8880b8fe9167bd3f0e483b037 (diff)
Merge branch 'master' of github.com:grpc/grpc into cpp_auth_md_processor
Diffstat (limited to 'examples/node/greeter_server.js')
-rw-r--r--examples/node/greeter_server.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/examples/node/greeter_server.js b/examples/node/greeter_server.js
new file mode 100644
index 0000000000..2fb95f0f90
--- /dev/null
+++ b/examples/node/greeter_server.js
@@ -0,0 +1,63 @@
+/*
+ *
+ * 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.
+ *
+ */
+
+var PROTO_PATH = __dirname + '/helloworld.proto';
+
+var grpc = require('grpc');
+var hello_proto = grpc.load(PROTO_PATH).helloworld;
+
+var Server = grpc.buildServer([hello_proto.Greeter.service]);
+
+/**
+ * Implements the SayHello RPC method.
+ */
+function sayHello(call, callback) {
+ callback(null, {message: 'Hello ' + call.request.name});
+}
+
+/**
+ * Starts an RPC server that receives requests for the Greeter service at the
+ * sample server port
+ */
+function main() {
+ var server = new Server({
+ "helloworld.Greeter": {
+ sayHello: sayHello
+ }
+ });
+
+ server.bind('0.0.0.0:50051');
+ server.listen();
+}
+
+main();