<commit_before>#!/usr/bin/node

var net = require('net');

clients = []
servers = []

//console.log(clients);

function bye(c) {
 if (clients.indexOf(c) > -1) {
    index = clients.indexOf(c);
    clients.splice(index, 1);
    //console.log("Clients: " + clients.length);
  } else if (servers.indexOf(c) > -1) {
    index = servers.indexOf(c);
    servers.splice(index, 1);
    //console.log("Servers: " + servers.length);
  }
};

server = net.createServer(function(c) {
  c.on('data', function(data) {
    //console.log(data.toString().trim());
    if (data.toString().trim() == 'S') {
      servers.push(c);
      //console.log(servers.length);
    } else if (data.toString().trim() == 'C') {
      clients.push(c);
      //console.log(clients.length);
    } else {
      if (data.toString()[data.length-1] == '\n') {
        if (servers.indexOf(c) > -1) {
          clients.forEach(function (sock) {
            sock.write(data);
          })
        } else if (clients.indexOf(c) > -1) {
          servers.forEach(function (sock) {
            sock.write(data);
          });
        } else {
          c.write('Servers: ' + servers.length + "\nClients: " + clients.length + "\n");
        };
      } else {
        console.log ('incomplete data');
        console.log(data.toString());
      };
    };
  });
  c.on('end', function() {
    bye(c);
  });
  c.on('error', function() {
    c.end();
    bye(c);<commit_msg>clean up data in transit<commit_after>#!/usr/bin/node

var net = require('net');

clients = []
servers = []

//console.log(clients);

function bye(c) {
 if (clients.indexOf(c) > -1) {
    index = clients.indexOf(c);
    clients.splice(index, 1);
    //console.log("Clients: " + clients.length);
  } else if (servers.indexOf(c) > -1) {
    index = servers.indexOf(c);
    servers.splice(index, 1);
    //console.log("Servers: " + servers.length);
  }
};

server = net.createServer(function(c) {
  oldData = '';
  c.on('data', function(data) {
    //console.log(data.toString().trim());
    if (data.toString().trim() == 'S') {
      servers.push(c);
      //console.log(servers.length);
    } else if (data.toString().trim() == 'C') {
      clients.push(c);
      //console.log(clients.length);
    } else {
      if (data.toString()[data.length-1] == '\n') {
        allData = oldData + data;
        if (oldData != '') {
          console.log("fixed some data");
          console.log(allData.length);
        }
        oldData = '';
        //console.log ('complete data ' + data.length );
        if (servers.indexOf(c) > -1) {
          clients.forEach(function (sock) {
            sock.write(allData);
          })
        } else if (clients.indexOf(c) > -1) {
          servers.forEach(function (sock) {
            sock.write(allData);
          });
        } else {
          c.write('Servers: ' + servers.length + "\nClients: " + clients.length + "\n");
        };
      } else {
        oldData = oldData + data
        //console.log ('incomplete data ' + data.length );
        //console.log(data.toString());
      };
    };
  });
  c.on('end', function() {
    bye(c);
  });
  c.on('error', function() {
    c.end();
    bye(c);
{'fraction_non_alphanumeric': 0.20347551342812006, 'fraction_numerical': 0.0044233807266982625, 'mean_word_length': 2.147117296222664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1620760', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1090, 'n_words': 180}