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