world.server.js 1011 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const ipc=require('../../../node-ipc');
  2. /***************************************\
  3. *
  4. * UDP Client is really a UDP server
  5. *
  6. * Dedicated UDP sockets on the same
  7. * machine can not be bound to in the
  8. * traditional client/server method
  9. *
  10. * Every UDP socket is it's own UDP server
  11. * And so must have a unique port on its
  12. * machine, unlike TCP or Unix Sockts
  13. * which can share on the same machine.
  14. *
  15. * Since there is no open client server
  16. * relationship, you should start world
  17. * first and then hello.
  18. *
  19. ***************************************/
  20. ipc.config.id = 'world';
  21. ipc.config.retry= 1500;
  22. ipc.config.rawBuffer=true;
  23. ipc.config.encoding='ascii';
  24. ipc.serveNet(
  25. 'udp4',
  26. function(){
  27. ipc.server.on(
  28. 'data',
  29. function(data,socket){
  30. ipc.log('got a message', data,data.toString());
  31. ipc.server.emit(
  32. socket,
  33. 'goodbye'
  34. );
  35. }
  36. );
  37. }
  38. );
  39. ipc.server.start();