Skip to content

Instantly share code, notes, and snippets.

@jcolebrand
Created October 13, 2011 17:58
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 jcolebrand/1284948 to your computer and use it in GitHub Desktop.
Save jcolebrand/1284948 to your computer and use it in GitHub Desktop.
For Jenan
<html xmlns="http://www.w3.org/1999/xhtml">
var app = require('http').createServer(handler)
, io = require('socket.io').listen(8000)
, fs = require('fs')
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.sockets.on('connection', function (socket) {
socket.on('chat', function (data) {
socket.broadcast.emit('chat', {
msg : data
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment