From: Jason Woofenden Date: Tue, 29 Jan 2013 23:12:24 +0000 (-0500) Subject: files testing/showing socket.io asynchiness X-Git-Tag: v1.0~46^2 X-Git-Url: https://jasonwoof.com/gitweb/?p=watch-my-terminal.git;a=commitdiff_plain;h=fd4626e8e9d799c21dadc73fa99d8c7625232516 files testing/showing socket.io asynchiness --- diff --git a/index.html b/index.html new file mode 100644 index 0000000..e55e8c0 --- /dev/null +++ b/index.html @@ -0,0 +1,9 @@ + + diff --git a/server.js b/server.js new file mode 100644 index 0000000..9936453 --- /dev/null +++ b/server.js @@ -0,0 +1,28 @@ +var app = require('http').createServer(handler) + , io = require('socket.io').listen(app) + , fs = require('fs') + +app.listen(9293); + +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) { + setInterval(function() { socket.emit('news', { hello: 'world' });}, 2000); + socket.on('my other event', function (data) { + console.log(data); + }); + socket.on('jason', function (data) { + console.log({jason_is_here: data}); + }); +});