Permalink
Browse files

Initial Commit

  • Loading branch information...
mheap committed Mar 4, 2013
0 parents commit 61151cbbc61ed916084a0bd83675c0971d7c09a7
Showing with 48 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +25 −0 app.js
  3. +8 −0 index.html
  4. +14 −0 package.json
@@ -0,0 +1 @@
node_modules
25 app.js
@@ -0,0 +1,25 @@
var app = require('http').createServer(handler)
, io = require('socket.io').listen(app)
, fs = require('fs')

app.listen(3000);

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.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
@@ -0,0 +1,8 @@
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
@@ -0,0 +1,14 @@
{
"name": "socket-example",
"version": "0.0.1",
"description": "ERROR: No README.md file found!",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": "",
"author": "Michael Heap <m@michaelheap.com>",
"dependencies": {
"socket.io": "~0.9.13"
}
}

0 comments on commit 61151cb

Please sign in to comment.