hello-client.js 1005 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. 'use strict';
  2. const ipc=require('../../../node-ipc');
  3. /***************************************\
  4. *
  5. * You should start both hello and world
  6. * then you will see them communicating.
  7. *
  8. * *************************************/
  9. ipc.config.id = 'hello';
  10. ipc.config.retry= 1500;
  11. ipc.config.rawBuffer=true;
  12. ipc.config.encoding='hex';
  13. ipc.connectTo(
  14. 'world',
  15. function(){
  16. ipc.of.world.on(
  17. 'connect',
  18. function(){
  19. //make a 6 byte buffer for example
  20. const myBuffer=new Buffer(6).fill(0);
  21. myBuffer.writeUInt16BE(0x02,0);
  22. myBuffer.writeUInt32BE(0xffeecc,2);
  23. ipc.log('## connected to world ##', ipc.config.delay);
  24. ipc.of.world.emit(
  25. myBuffer
  26. );
  27. }
  28. );
  29. ipc.of.world.on(
  30. 'data',
  31. function(data){
  32. ipc.log('got a message from world : ', data);
  33. }
  34. );
  35. }
  36. );