<commit_before>'use strict';

var SoftAP = require('./SoftAP');
var util = require('util');
var net = require('net');

function TcpSoftAP(options) {
	SoftAP.call(this, options);
}
util.inherits(TcpSoftAP, SoftAP);

TcpSoftAP.prototype._sendProtocolCommand = function _sendProtocolCommand(cmd, cb) {
	var err, json;
	var data = '';

	var sock = net.createConnection(this.port, this.host);
	sock.setNoDelay(this.noDelay);
	sock.setTimeout(this.timeout);
	sock.setKeepAlive(this.keepAlive);

	var to = setTimeout(function socketTimedOut() {
		err = new Error('TCP socket timed out');
		sock.destroy();
	}, this.timeout);

	sock.once('connect', function socketConnected() {
		var send;
		if (cmd.body && typeof cmd.body === 'object') {
			var body = JSON.stringify(cmd.body);
			var length = body.length;
			send = util.format('%s\n%s\n\n%s', cmd.name, length, body);
		} else {
			send = util.format('%s\n0\n\n', cmd.name);
		}

		sock.write(send);
	});

	sock.on('data', function socketData(chunk) {
		data += chunk.toString();
		try {
			json = JSON.parse(data);
			clearTimeout(to);
			sock.end();
		} catch (e) {
			// Wait for more data to come in
		}<commit_msg>fixes issue #23 - do not close the socket since this is done already by the device.<commit_after>'use strict';

var SoftAP = require('./SoftAP');
var util = require('util');
var net = require('net');

function TcpSoftAP(options) {
	SoftAP.call(this, options);
}
util.inherits(TcpSoftAP, SoftAP);

TcpSoftAP.prototype._sendProtocolCommand = function _sendProtocolCommand(cmd, cb) {
	var err, json;
	var data = '';

	var sock = net.createConnection(this.port, this.host);
	sock.setNoDelay(this.noDelay);
	sock.setTimeout(this.timeout);
	sock.setKeepAlive(this.keepAlive);

	var to = setTimeout(function socketTimedOut() {
		err = new Error('TCP socket timed out');
		sock.destroy();
	}, this.timeout);

	sock.once('connect', function socketConnected() {
		var send;
		if (cmd.body && typeof cmd.body === 'object') {
			var body = JSON.stringify(cmd.body);
			var length = body.length;
			send = util.format('%s\n%s\n\n%s', cmd.name, length, body);
		} else {
			send = util.format('%s\n0\n\n', cmd.name);
		}

		sock.write(send);
	});

	sock.on('data', function socketData(chunk) {
		data += chunk.toString();
		try {
			json = JSON.parse(data);
			clearTimeout(to);
		} catch (e) {
			// Wait for more data to come in
		}
{'fraction_non_alphanumeric': 0.16729559748427672, 'fraction_numerical': 0.0016771488469601676, 'mean_word_length': 4.055084745762712, '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': '2174866', 'n_tokens_mistral': 894, 'n_tokens_neox': 829, 'n_words': 194}