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.

21 lines
607 B

  1. var WebSocketServer = require('../../').Server
  2. , http = require('http')
  3. , express = require('express')
  4. , app = express();
  5. app.use(express.static(__dirname + '/public'));
  6. var server = http.createServer(app);
  7. server.listen(8080);
  8. var wss = new WebSocketServer({server: server});
  9. wss.on('connection', function(ws) {
  10. var id = setInterval(function() {
  11. ws.send(JSON.stringify(process.memoryUsage()), function() { /* ignore errors */ });
  12. }, 100);
  13. console.log('started client interval');
  14. ws.on('close', function() {
  15. console.log('stopping client interval');
  16. clearInterval(id);
  17. });
  18. });