Browse files

got basic socket.io working, added static index.html file

  • Loading branch information...
1 parent eecf58e commit 8ab39cf0e9fb879f3cb2a6bfbe8e959d4f748520 @nhoss2 committed May 28, 2012
Showing with 26 additions and 11 deletions.
  1. +4 −4 index.js
  2. +11 −0 static/index.html
  3. +11 −7 static/socketio.js
View
8 index.js
@@ -42,7 +42,7 @@ app.use('/', function(req, res){
res.writeHead(200);
- res.write('<html>\n<head><script type="text/javascript" src="/socket.io/socket.io.js"></script><script type="text/javascript" src="/static/socketio.js"></script><script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script></head><body>' + mdLinks);
+ res.write(fs.readFileSync('static/index.html', 'utf-8') + mdLinks);
res.end('</body></html>');
});
@@ -52,10 +52,10 @@ io = socketio.listen(server);
io.sockets.on('connection', function (socket){
socket.emit('hello', {message: 'hello!'});
-});
-io.sockets.on('readFile', function (file){
- console.log('readFile recieved, file: ' + file.name);
+ socket.on('readFile', function (file){
+ console.log('readFile recieved, file: ' + file.name);
+ });
});
View
11 static/index.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<script type="text/javascript" src="/socket.io/socket.io.js"></script>
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
+<script type="text/javascript" src="/static/socketio.js"></script>
+</head>
+
+<body>
+
+
+
View
18 static/socketio.js
@@ -1,11 +1,15 @@
-var socket = io.connect('http://localhost:8888');
-socket.on('hello', function (data){
- console.log(data.message);
-});
$(document).ready(function(){
- $(a).click(function(){
- alert('a clicked');
- socket.emit('readFile', {name: 'test.md'});
+
+ var socket = io.connect();
+ socket.on('connect', function(){
+ socket.on('hello', function (data){
+ console.log(data.message);
+ });
+
+ $('a').click(function(){
+ socket.emit('readFile', {name: 'test.md'});
+ });
});
+
});

0 comments on commit 8ab39cf

Please sign in to comment.