You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
732 B

  1. var WebSocketServer = require('../').Server;
  2. process.on('uncaughtException', function(err) {
  3. console.log('Caught exception: ', err, err.stack);
  4. });
  5. process.on('SIGINT', function () {
  6. try {
  7. console.log('Updating reports and shutting down');
  8. var ws = new WebSocket('ws://localhost:9001/updateReports?agent=ws');
  9. ws.on('close', function() {
  10. process.exit();
  11. });
  12. }
  13. catch(e) {
  14. process.exit();
  15. }
  16. });
  17. var wss = new WebSocketServer({port: 8181});
  18. wss.on('connection', function(ws) {
  19. console.log('new connection');
  20. ws.on('message', function(data, flags) {
  21. ws.send(flags.buffer, {binary: flags.binary === true});
  22. });
  23. ws.on('error', function() {
  24. console.log('error', arguments);
  25. });
  26. });