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 = 1000;
  10. ipc.config.sync= true;
  11. ipc.connectTo(
  12. 'world',
  13. function(){
  14. ipc.of.world.on(
  15. 'connect',
  16. function(){
  17. ipc.log('## connected to world ##', ipc.config.delay);
  18. //queue up a bunch of requests to be sent synchronously
  19. for(var i=0; i<10; i++){
  20. ipc.of.world.emit(
  21. 'app.message',
  22. {
  23. id : ipc.config.id,
  24. message : 'hello'+i
  25. }
  26. );
  27. }
  28. }
  29. );
  30. ipc.of.world.on(
  31. 'disconnect',
  32. function(){
  33. ipc.log('disconnected from world');
  34. }
  35. );
  36. ipc.of.world.on(
  37. 'app.message',
  38. function(data){
  39. ipc.log('got a message from world : ', data);
  40. }
  41. );
  42. console.log(ipc.of.world.destroy);
  43. }
  44. );