world.server.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const ipc=require('../../../node-ipc');
  2. /***************************************\
  3. *
  4. * You should start both hello and world
  5. * then you will see them communicating.
  6. *
  7. * *************************************/
  8. ipc.config.id = 'world';
  9. ipc.config.retry= 1500;
  10. ipc.config.rawBuffer=true;
  11. ipc.config.encoding='ascii';
  12. ipc.config.networkHost='localhost';
  13. ipc.config.tls={
  14. public: __dirname+'/../../../local-node-ipc-certs/server.pub',
  15. private: __dirname+'/../../../local-node-ipc-certs/private/server.key',
  16. dhparam: __dirname+'/../../../local-node-ipc-certs/private/dhparam.pem',
  17. requestCert: true,
  18. rejectUnauthorized:true,
  19. trustedConnections: [
  20. __dirname+'/../../../local-node-ipc-certs/client.pub'
  21. ]
  22. };
  23. ipc.serveNet(
  24. function(){
  25. ipc.server.on(
  26. 'connect',
  27. function(socket){
  28. console.log('connection detected');
  29. ipc.server.emit(
  30. socket,
  31. 'hello'
  32. );
  33. }
  34. );
  35. ipc.server.on(
  36. 'data',
  37. function(data,socket){
  38. ipc.log('got a message', data,data.toString());
  39. ipc.server.emit(
  40. socket,
  41. 'goodbye'
  42. );
  43. }
  44. );
  45. }
  46. );
  47. ipc.server.start();