Skip to content

Commit

Permalink
Added the first experiment with socket.io
Browse files Browse the repository at this point in the history
  • Loading branch information
jettro committed Mar 18, 2011
1 parent 9e7a9b1 commit 86e692b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
14 changes: 13 additions & 1 deletion src/app.js
Expand Up @@ -37,4 +37,16 @@ app.post('/blog/new', function (req, res) {
});

app.listen(3000);
console.log('Express server started on port %s', app.address().port);
console.log('Express server started on port %s', app.address().port);

var io = require('socket.io');
var socket = io.listen(app);
socket.on('connection', function(client) {
console.log('A client connected');
client.on('message',function() {
console.out('Receveived a message from the client');
});
client.on('disconnect', function() {
console.out('Client disconnected');
});
});
Binary file added src/public/favicon.ico
Binary file not shown.
12 changes: 12 additions & 0 deletions src/public/javascript/socket-connect.js
@@ -0,0 +1,12 @@
var node_server_url='/';
var socket = new io.Socket(node_server_url);
socket.connect();
socket.on('connect', function() {
alert('Connected to the server');
});
socket.on('message', function(){
alert('Receiving a message');
});
socket.on('disconnect', function(){
alert('Disconnected from server');
});
2 changes: 1 addition & 1 deletion src/views/blog.jade
Expand Up @@ -7,4 +7,4 @@ div#articles
div.title #{blog.title}
div.created_at #{blog.created_at}
div.body #{blog.body}

div#helloworld
12 changes: 7 additions & 5 deletions src/views/layout.jade
@@ -1,7 +1,9 @@
!!! 5
html(lang="en")
head
title My Blog
link(href="/style/style.css", media="screen", rel="stylesheet", type="text/css")
body
div!= body
head
title My Blog
link(href="/style/style.css", media="screen", rel="stylesheet", type="text/css")
script(src='/socket.io/socket.io.js')
script(src='/javascript/socket-connect.js')
body
div!= body

0 comments on commit 86e692b

Please sign in to comment.