Skip to content
This repository has been archived by the owner on Nov 8, 2020. It is now read-only.

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mheap committed Mar 4, 2013
0 parents commit 61151cb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
25 changes: 25 additions & 0 deletions 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);
});
});
8 changes: 8 additions & 0 deletions index.html
@@ -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>
14 changes: 14 additions & 0 deletions package.json
@@ -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.