diff options
Diffstat (limited to 'socket.io/sio2.js')
-rw-r--r-- | socket.io/sio2.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/socket.io/sio2.js b/socket.io/sio2.js new file mode 100644 index 0000000..6d44c37 --- /dev/null +++ b/socket.io/sio2.js @@ -0,0 +1,24 @@ +/* probably want to use this approach for socket.io */ + +var express = require('express'); +var http = require('http'); +var io = require('socket.io'); +var path = require('path'); + +var app = express(); +var server = http.createServer(app).listen(8081); +var sio = io.listen(server); + +app.use(express.static(path.join(__dirname, 'public'))); + +app.get('/', function (req, res) { + res.send('hello, world!'); +}); + +sio.sockets.on('connection', function (socket) { + socket.emit('news', 'hello there stranger'); + socket.on('my other event', function (data) { + console.log(data); + }); +}); + |