<commit_before>var net = require('net'),
    util = require('util'),
    EventEmitter = require('events').EventEmitter,
    SocketPlayer = require('./socket-player');

module.exports = SocketServer;

function SocketServer(host, socketPort) {
    this._host = host;
    this._socketPort = socketPort;
    this._server = null;
    EventEmitter.call(this);
}

util.inherits(SocketServer, EventEmitter);

SocketServer.prototype.start = function(callback) {
    var self = this;
    self._server = net.createServer();
    self._server.listen(self._socketPort, self._host, function(err) {
        self._server.on('connection', function(socket) {self._onConnection(socket);});
        console.log('Socket server listening on ' + self._server.address().address +':'+ self._server.address().port);
        callback(err);
    });
};

SocketServer.prototype._onConnection = function(socket) {

    var socketPlayer = new SocketPlayer(socket);
    this.emit("new_player", socketPlayer);

};<commit_msg>Add comments<commit_after>var net = require('net'),
    util = require('util'),
    EventEmitter = require('events').EventEmitter,
    SocketPlayer = require('./socket-player');

module.exports = SocketServer;

/**
 * Creates SocketServer. Call `start`-method to start the server.
 * @param {string}  host          Host where clients must connect to. Set to undefined to listen all ipv4 addresses.
 * @param {int}     socketPort    Port to listen.
 * @constructor
 * @extends EventEmitter
 */
function SocketServer(host, socketPort) {
    this._host = host;
    this._socketPort = socketPort;
    this._server = null;
    EventEmitter.call(this);
}

util.inherits(SocketServer, EventEmitter);

/**
 * Callback used by start function.
 * @callback SocketServer~startCallback
 * @param {string|null} err     Error string if an error occurred.
 */
/**
 * Starts the server
 * @param {SocketServer~startCallback} callback     Callback function.
 */
SocketServer.prototype.start = function(callback) {
    var self = this;
    self._server = net.createServer();
    self._server.listen(self._socketPort, self._host, function(err) {
        self._server.on('connection', function(socket) {self._onConnection(socket);});
        console.log('Socket server listening on ' + self._server.address().address +':'+ self._server.address().port);
        callback(err);
    });
};

/**
 * Handles new connections.
 * @param {object} socket       Socket handle of the connected client.
 * @private
 */
SocketServer.prototype._onConnection = function(socket) {

    var socketPlayer = new SocketPlayer(socket);
    this.emit("new_player", socketPlayer);
};
{'fraction_non_alphanumeric': 0.13688212927756654, 'fraction_numerical': 0.00038022813688212925, 'mean_word_length': 3.908582089552239, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2056493', 'n_tokens_mistral': 743, 'n_tokens_neox': 745, 'n_words': 174}