Nodejs应用程序如何调用grpc服务器

我试图弄清楚如何从我的nodejs应用程序中的javascript函数调用grpc服务器,并更新我的页面…我不知道如何pipe理它。

这是原始文件:

syntax = "proto3"; package helloworld; service Greeter { rpc SayHello (HelloRequest) returns (HelloReply) {} } message HelloRequest { string name = 1; } message HelloReply { string message = 1; } 

这是服务器:

 var PROTO_PATH = __dirname + '/helloworld.proto'; var grpc = require('grpc'); var hello_proto = grpc.load(PROTO_PATH).helloworld; function sayHello(call, callback) { callback(null, {message: 'Hello ' + call.request.name}); } function main() { var server = new grpc.Server(); server.addProtoService(hello_proto.Greeter.service, {sayHello: sayHello}); server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); server.start(); } main(); 

这是javascript的function:

 var PROTO_PATH = __dirname + '/helloworld.proto'; var grpc = require('grpc'); var hello_proto = grpc.load(PROTO_PATH).helloworld; function test() { var client = new hello_proto.Greeter('localhost:50051', grpc.credentials.createInsecure()); client.sayHello(function(err, response) { console.log('Greeting:', response.message); document.getElementById("para").innerHTML = 'Mex Received from grpc server ' + response.message; }); } 

当我点击我的网页上的一个button我打电话functiontesting,我想更新元素(id = para)。

任何想法?