-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.js
30 lines (25 loc) · 790 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var readline = require('readline');
var grpc = require('grpc');
var helloworld = grpc.load('./protos/hello_world.proto').helloworld;
var client = new helloworld.HelloWorld('localhost:50051', grpc.credentials.createInsecure());
client.sayHello('Shawn', function(err, response) {
console.log('');
console.log('Greeting:', response.text);
console.log('');
console.log('Enter your own name to get a streaming response (or Ctrl+C to exit):');
});
const stream = client.sayHelloStreamingRequestResponse();
stream.on('data', ({ text }) => {
console.log(text);
})
stream.on('end', () => {
cliend.end();
});
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
stream.write({ name: line });
});