hello-client.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const ipc=require('../../../node-ipc');
  2. /***************************************\
  3. *
  4. * Since there is no client relationship
  5. * with UDP sockets sockets are not kept
  6. * open.
  7. *
  8. * This means the order sockets are opened
  9. * is important.
  10. *
  11. * Start World first. Then you can start
  12. * hello or goodbye in any order you
  13. * choose.
  14. *
  15. * *************************************/
  16. ipc.config.id = 'hello';
  17. ipc.config.retry= 1500;
  18. ipc.serveNet(
  19. 8001, //we set the port here because the world server is already using the default of 8000. So we can not bind to 8000 while world is using it.
  20. 'udp4',
  21. function(){
  22. ipc.server.on(
  23. 'message',
  24. function(data){
  25. ipc.log('got Data');
  26. ipc.log('got a message from ', data.id ,' : ', data.message);
  27. }
  28. );
  29. ipc.server.emit(
  30. {
  31. address : 'localhost',
  32. port : ipc.config.networkPort
  33. },
  34. 'message',
  35. {
  36. id : ipc.config.id,
  37. message : 'Hello'
  38. }
  39. );
  40. }
  41. );
  42. ipc.server.start();