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