Created
February 1, 2012 15:48
-
-
Save davidfooks/1717643 to your computer and use it in GitHub Desktop.
A server highlighting bug https://github.com/LearnBoost/socket.io/issues/430
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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