hello-client.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 = 'hello';
  9. ipc.config.retry= 1500;
  10. ipc.connectTo(
  11. 'world',
  12. function(){
  13. ipc.of.world.on(
  14. 'connect',
  15. function(){
  16. ipc.log('## connected to world ##', ipc.config.delay);
  17. ipc.of.world.emit(
  18. 'app.message',
  19. {
  20. id : ipc.config.id,
  21. message : 'hello'
  22. }
  23. );
  24. }
  25. );
  26. ipc.of.world.on(
  27. 'disconnect',
  28. function(){
  29. ipc.log('disconnected from world');
  30. }
  31. );
  32. ipc.of.world.on(
  33. 'app.message',
  34. function(data){
  35. ipc.log('got a message from world : ', data);
  36. }
  37. );
  38. ipc.of.world.on(
  39. 'kill.connection',
  40. function(data){
  41. ipc.log('world requested kill.connection');
  42. ipc.disconnect('world');
  43. }
  44. );
  45. }
  46. );