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