Created
July 2, 2010 22:25
-
-
Save anoras/461993 to your computer and use it in GitHub Desktop.
Code for my screencast at http://vimeo.com/13043828
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-latest.min.js"></script> | |
<script src="client/socket.io.js" type="text/javascript" charset="utf-8"></script> | |
<script type="text/javascript" charset="utf-8"> | |
var socket = new io.Socket(null, {rememberTransport: false, port: 8080}); | |
socket.connect(); | |
socket.addEvent('message', function(data) { | |
$('body').append('<p>' + $.map(data, function(e,i) { | |
return String.fromCharCode(e); | |
}).join('') + '</p>'); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or 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 http = require('http'), | |
url = require('url'), | |
path = require('path'), | |
fs = require('fs'), | |
io = require('../lib/socket.io'), | |
sys = require('sys'); | |
server = http.createServer(function(request, response){ | |
var uri = url.parse(request.url).pathname; | |
var filename = path.join(process.cwd(), uri); | |
path.exists(filename, function(exists) { | |
if (!exists) { | |
response.writeHeader(404, {'Content-Type':'text/plain'}); | |
response.end("Can''t find it..."); | |
} | |
fs.readFile(filename, 'binary',function(err, file){ | |
if (err) { | |
response.writeHeader(500, {'Content-Type':'text/plain'}); | |
response.end(err + "\n"); | |
return; | |
} | |
response.sendHeader(200); | |
response.write(file, 'binary'); | |
response.close(); | |
}); | |
}); | |
}); | |
server.listen(8080); | |
var listner = io.listen(server); | |
process.openStdin().addListener("data", function(text) { | |
listner.broadcast(text); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment