No errors, no response to my client. My message.proto:
syntax = "proto3";
message TstCoordinates {
required int32 id = 1;
required string firstname = 2;
required string lastname = 3;
required string email = 4;
required string areacode = 5;
required string phone = 6;
required string extension = 7;
}
message TstId {
required int32 id = 1;
}
message Empty {}
service TstService{
rpc SendCoordinates (TstId) returns (TstCoordinates);
rpc List (Empty) returns (TstCoordinates);
}
My gRPC server:
'use strict';
const fs = require('fs');
const grpc = require('grpc');
const serviceDef = grpc.load("message.proto");
const PORT = 7777;
const cacert = fs.readFileSync('certs/ca.crt'),
cert = fs.readFileSync('certs/server.crt'),
key = fs.readFileSync('certs/server.key'),
kvpair = {
'private_key': key,
'cert_chain': cert
};
const creds = grpc.ServerCredentials.createSsl(cacert, [kvpair]);
var tstcoordinates = [
{
id: 1,
firstname: "Bill",
lastname: "Williams",
email: "williams@example.com",
areacode: "444",
phone: "555-1212",
extension: "378"
},
{
id: 2,
firstname: "Happy",
lastname: "Golucky",
email: "lucky@example.com",
areacode: "444",
phone: "555-1212",
extension: "382"
}
];
var server = new grpc.Server();
server.addService(serviceDef.TstService.service, {
list: function(call, callback) {
console.log("in list");
callback(null, tstcoordinates);
},
sendCoordinates: function(call, callback) {
console.log("in sendCoordinates");
callback(null, tstcoordinates[0] );
return;
}
});
server.bind(`0.0.0.0:${PORT}`, creds);
console.log(`Starting gRPC server on port ${PORT}`);
server.start();
My client:
'use strict';
const fs = require('fs');
const process = require('process');
const grpc = require('grpc');
const serviceDef = grpc.load("message.proto");
const PORT = 7777;
const cacert = fs.readFileSync('certs/ca.crt'),
cert = fs.readFileSync('certs/client.crt'),
key = fs.readFileSync('certs/client.key'),
kvpair = {
'private_key': key,
'cert_chain': cert
};
const creds = grpc.credentials.createSsl(cacert, key, cert);
const client = new serviceDef.TstService(`hyperledger-devenv:${PORT}`,creds);
console.log("secure connection established with gRPC server");
lst();
snd();
function printResponse(error, response) {
console.log("in printResponse");
if (error)
console.log('Error: ', error);
else
console.log(response);
}
function lst() {
console.log("in list");
client.list({}, function(error, response) {
console.log("in list call");
printResponse(error, response);
});
}
function snd() {
console.log("in snd");
client.sendCoordinates({'id': 1}, function(error, response) {
console.log("in snd call");
printResponse(error, response);
});
}
When I do a "curl localhost:7777" command, the server displays an SSL handshake error so I know it's listening. The client displays:
secure connection established with gRPC server
in list
in snd
And that's all. No errors on either side. I tried without SSL and get exactly the same result.
My versions: node --version v6.9.5
protoc --version libprotoc 2.6.1
npm --version 3.10.10
Any help greatly appreciated.
TIA
via user3597426
No comments:
Post a Comment