world-server.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.serveNet(
  23. 'udp4',
  24. function(){
  25. ipc.server.on(
  26. 'message',
  27. function(data,socket){
  28. ipc.log('got a message from ', data.id ,' : ', data.message);
  29. ipc.server.emit(
  30. socket,
  31. 'message',
  32. {
  33. id : ipc.config.id,
  34. message : data.message+' world!'
  35. }
  36. );
  37. }
  38. );
  39. }
  40. );
  41. ipc.server.start();