summaryrefslogtreecommitdiffstats
path: root/socket.io/sio2.js
blob: 6d44c3728e0be113b186031c43e1a8c538a807b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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);
    });
});