client. With a "streaming client <--> streaming server" when
- I call the .end() method on the client object, the .on('end') event is called on the server
- I disconnect the client code with ctrl+c, also the .on('end') event is called on the server
(I shared my code below.)
it means that the server will understand that a client is dead(disconnected), so there will be no more resource consumption on the server. Did I miss something or not?
I don't know how to implement the heart-beat on this situations, any clue would be appreciated.
Server.js
var PROTO_PATH = __dirname + '/../../protos/hellostreamingworld.proto';
var grpc = require('grpc');
var hello_proto = grpc.load(PROTO_PATH).hellostreamingworld;
/**
* Implements the SayHello RPC method.
*/
function sayHello(call) {
call.on('data', () => {
call.write('recieved')
})
call.on('end', () => {
console.log(call.request);
})
console.log("call object is: ", call);
}
/**
* Starts an RPC server that receives requests for the Greeter service at the
* sample server port
*/
function main() {
var server = new grpc.Server();
server.addProtoService(hello_proto.MultiGreeter.service, {sayHello: sayHello});
server.bind('localhost:50051', grpc.ServerCredentials.createInsecure());
server.start();
console.log('server is running :) ')
}
main();
Client.js
var PROTO_PATH = __dirname + '/../../protos/hellostreamingworld.proto';
var grpc = require('grpc');
var hello_proto = grpc.load(PROTO_PATH).hellostreamingworld;
var client = new hello_proto.MultiGreeter('localhost:50051', grpc.credentials.createInsecure());
var user;
if (process.argv.length >= 3) {
user = process.argv[2];
} else {
user = "world";
}
call = client.sayHello()
call.on('data', (message) => {
console.log("server said: [%s]", message.message);
})
call.on('end', () => {
console.log("end @ client");
})
call.write({name: "hadi", num_greetings: "a"})
call.write({name: "hadi", num_greetings: "a"})
call.end() // you can ommit this and stop the process by ctrl-c. same behaviour