JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
files testing/showing socket.io asynchiness
authorJason Woofenden <jason@jasonwoof.com>
Tue, 29 Jan 2013 23:12:24 +0000 (18:12 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 29 Jan 2013 23:12:24 +0000 (18:12 -0500)
index.html [new file with mode: 0644]
server.js [new file with mode: 0644]

diff --git a/index.html b/index.html
new file mode 100644 (file)
index 0000000..e55e8c0
--- /dev/null
@@ -0,0 +1,9 @@
+<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' });
+    socket.emit('jason', { is: 'large and in charge' });
+  });
+</script>
diff --git a/server.js b/server.js
new file mode 100644 (file)
index 0000000..9936453
--- /dev/null
+++ b/server.js
@@ -0,0 +1,28 @@
+var app = require('http').createServer(handler)
+  , io = require('socket.io').listen(app)
+  , fs = require('fs')
+
+app.listen(9293);
+
+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) {
+  setInterval(function() { socket.emit('news', { hello: 'world' });}, 2000);
+  socket.on('my other event', function (data) {
+    console.log(data);
+  });
+  socket.on('jason', function (data) {
+    console.log({jason_is_here: data});
+  });
+});