Skip to content

Commit

Permalink
basic socket.io integration
Browse files Browse the repository at this point in the history
  • Loading branch information
btouellette authored and btouellette committed Apr 2, 2014
1 parent aa34c41 commit 918113e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"connect-flash": "~0.1.1",
"bcrypt-nodejs": "latest",
"tunnel": "0.0.3",
"url": "^0.7.9"
"socket.io": "^0.9.16"
}
}
12 changes: 10 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,13 @@ app.configure(function() {
require('./app/routes.js')(app, passport); // load our routes and pass in our app and fully configured passport

// launch ======================================================================
app.listen(port);
console.log('The magic happens on port ' + port);
var server = app.listen(port);
var io = require('socket.io').listen(server);
console.log('The magic happens on port ' + port);

io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
9 changes: 8 additions & 1 deletion views/index.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@
<p>A demo by <a href="http:https://scotch.io">Scotch</a>.</p>
<p>Visit the <a href="http:https://scotch.io/tutorials/javascript/easy-node-authentication-setup-and-local">tutorial</a>.</p>
</div>

<script src="//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js"></script>
<script>
var socket = io.connect('http:https://localhost:5000');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
</div>
</body>
</html>

0 comments on commit 918113e

Please sign in to comment.