world-server.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. var messages={
  11. goodbye:false,
  12. hello:false
  13. };
  14. ipc.serve(
  15. function(){
  16. ipc.server.on(
  17. 'app.message',
  18. function(data,socket){
  19. ipc.log('got a message from', (data.id), (data.message));
  20. messages[data.id]=true;
  21. ipc.server.emit(
  22. socket,
  23. 'app.message',
  24. {
  25. id : ipc.config.id,
  26. message : data.message+' world!'
  27. }
  28. );
  29. if(messages.hello && messages.goodbye){
  30. ipc.log('got all required events, telling clients to kill connection');
  31. ipc.server.broadcast(
  32. 'kill.connection',
  33. {
  34. id:ipc.config.id
  35. }
  36. );
  37. }
  38. }
  39. );
  40. }
  41. );
  42. ipc.server.start();