JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Merge branch 'feature/socket-test' into develop
[watch-my-terminal.git] / server.js
1 var app = require('http').createServer(handler)
2   , io = require('socket.io').listen(app)
3   , fs = require('fs')
4
5 app.listen(9293);
6
7 function handler (req, res) {
8   fs.readFile(__dirname + '/index.html',
9   function (err, data) {
10     if (err) {
11       res.writeHead(500);
12       return res.end('Error loading index.html');
13     }
14
15     res.writeHead(200);
16     res.end(data);
17   });
18 }
19
20 io.sockets.on('connection', function (socket) {
21   setInterval(function() { socket.emit('news', { hello: 'world' });}, 2000);
22   socket.on('my other event', function (data) {
23     console.log(data);
24   });
25   socket.on('jason', function (data) {
26     console.log({jason_is_here: data});
27   });
28 });