world-server.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. ipc.config.sync = true;
  11. ipc.serveNet(
  12. function(){
  13. ipc.server.on(
  14. 'message',
  15. function(data,socket){
  16. ipc.log('got a message : ', data);
  17. //fake some synch procedural code
  18. setTimeout(
  19. function(){
  20. ipc.server.emit(
  21. socket,
  22. 'message',
  23. data+' world!'
  24. );
  25. },
  26. 3000
  27. );
  28. }
  29. );
  30. ipc.server.on(
  31. 'socket.disconnected',
  32. function(data,socket){
  33. console.log(arguments);
  34. }
  35. );
  36. }
  37. );
  38. ipc.server.start();