-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
29 lines (24 loc) · 695 Bytes
/
server.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
var grpc = require('grpc');
var helloworld = grpc.load('./protos/hello_world.proto').helloworld;
function main() {
var server = new grpc.Server();
server.addProtoService(helloworld.HelloWorld.service, {
sayHello: (call, callback) => {
callback(null, { text: `Hello ${call.request.name}!` });
},
sayHelloStreamingRequestResponse: (call) => {
call.on('data', (data) => {
call.write(`Hello, ${data.name}!`);
})
call.on('end', () => {
call.end();
});
},
sayHelloStreamingResponse: (call) => {
call.send()
}
});
server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
server.start();
}
main();