cluster-client.js 551 B

12345678910111213141516171819202122232425262728293031
  1. const fs = require('fs');
  2. const ipc = require('../../node-ipc');
  3. const socketPath = '/tmp/ipc.sock';
  4. //loop forever so you can see the pid of the cluster sever change in the logs
  5. setInterval(
  6. function() {
  7. ipc.connectTo(
  8. 'world',
  9. socketPath,
  10. connecting
  11. );
  12. },
  13. 2000
  14. );
  15. function connecting(socket) {
  16. ipc.of.world.on(
  17. 'connect',
  18. function() {
  19. ipc.of.world.emit(
  20. 'currentDate',
  21. {
  22. message: new Date().toISOString()
  23. }
  24. );
  25. ipc.disconnect('world');
  26. }
  27. );
  28. }