{"size": 988, "ext": "js", "max_stars_repo_path": "js/node/socket_io_chat/app.js", "max_stars_repo_name": "10sr/junks", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/node/socket_io_chat/app.js", "max_issues_repo_name": "10sr/junks", "max_issues_repo_issues_event_min_datetime": "2016-07-19T04:59:00.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-30T02:10:06.000Z", "max_forks_repo_path": "js/node/socket_io_chat/app.js", "max_forks_repo_name": "10sr/junks", "max_forks_repo_forks_event_min_datetime": "2018-05-21T06:35:00.000Z", "max_forks_repo_forks_event_max_datetime": "2018-05-21T06:35:00.000Z"}
{"max_stars_count": null, "max_issues_count": 24, "max_forks_count": 1, "avg_line_length": 27.4444444444, "max_line_length": 77, "alphanum_fraction": 0.6406882591}
// http://www.tettori.net/post/852/

var http = require('http');
var socketio = require('socket.io');
var fs = require('fs');

var server = http.createServer(function(req, res){
    res.writeHead(200, {'Content-Type': 'text/html'});
    var output = fs.readFileSync('./index.html', 'utf-8');
    res.end(output);
}).listen(3000);

var io = socketio.listen(server);

io.sockets.on('connection', function(socket){

    // custom event
    socket.on('C_to_S_message', function(data){
        // all including the client sent the message
        io.sockets.emit('S_to_C_message', {value: data.value});
    });

    // custom event
    socket.on('C_to_S_broadcast', function(data){
        // all except the client (use obj passed throug arg of io.sockets.on)
        socket.broadcast.emit('S_to_C_message', {value: data.value});
    });

    socket.on('disconnect', function(){
        console.log('client disconnected');
    });
});


console.log('Server running at http://127.0.0.1:3000');
