Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2. const grpc = require('grpc');
  3. const path = require('path');
  4. const PROTO_PATH = path.join(__dirname, '/proto/p2p.proto');
  5. const DEFAULT_PORT = '40057';
  6. const p2p_proto = grpc.load(PROTO_PATH).p2p;
  7.  
  8. function PingPong(call, callback) {
  9.   console.log(call);
  10.   callback(null, { pong: 'ABCDEFGH12345678' });
  11. }
  12.  
  13. const server = new grpc.Server();
  14. server.addService(p2p_proto.Common.service, { PingPong: PingPong });
  15. server.bind('0.0.0.0:' + DEFAULT_PORT, grpc.ServerCredentials.createInsecure());
  16. server.start();
  17.  
  18.  
  19. const client = new p2p_proto.Common('localhost:' + DEFAULT_PORT,
  20.   grpc.credentials.createInsecure());
  21.  
  22.  
  23. setInterval(() => client.PingPong({ ping: 'ZZZZAAAAQQQQ' }, function (err, response) {
  24.   console.log('echo reply:', response.pong);
  25. }), 1000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement