Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var express = require('express');
var io = require('socket.io');
var http = require('http');
var fs = require('fs');
http.createServer(function (request, response) {
console.log('request ' + request.url);
fs.readFile('.' + request.url, function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
response.writeHead(200, { 'Content-Type': 'text/html' });
response.end(content, 'utf-8');
}
});
}).listen(8125);
var app = express.createServer();
var io = io.listen(app);
app.listen(8088);
var clientCount = 0;
io.sockets.on('connection', function (socket) {
socket.set('clientCount', clientCount);
console.log('new client: ' + clientCount);
clientCount += 1;
socket.on('heartbeat', function (count) {
socket.get('clientCount', function (err, clientCount)
{
console.log(clientCount + ': Heartbeat ' + count);
});
});
socket.on('disconnect', function (count) {
socket.get('clientCount', function (err, clientCount)
{
console.log('client disconnect: ' + clientCount);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment