Skip to content

Instantly share code, notes, and snippets.

@davidfooks
Created February 1, 2012 15:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfooks/1717643 to your computer and use it in GitHub Desktop.
Save davidfooks/1717643 to your computer and use it in GitHub Desktop.
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