<commit_before>﻿using System;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace SocketLib {
    
    public class Client : IDisposable {

        public delegate void OnDisconnectHandler();

        public event OnDisconnectHandler OnDisconnect;
        
        public delegate void OnMessageHandler(string message);

        public event OnMessageHandler OnMessage;
        
        protected Socket socket;
        protected Task listenTask;
        protected bool running;
        
        public bool debugEnabled { get; protected set; }
        protected StreamWriter debugFile;

        public Client(Socket socket) {
            this.socket = socket;
            socket.ReceiveTimeout = 1000;
            running = true;
            listenTask = new Task(() => {
                Byte[] received = new Byte[256];
                string message = "";
                
                while (running) {
                    if (socket.Available > 0) {
                        int bytes = socket.Receive(received, received.Length, 0);
                        message += Encoding.ASCII.GetString(received, 0, bytes);

                        if (message.Length != 0) {
                            if (OnMessage != null) OnMessage(message);

                            if (debugEnabled)
                                debugFile.WriteLine(DateTime.Now.ToShortTimeString() + " -- RECEIVED -- " + message);
                            <commit_msg>Fix long messages getting sent as two<commit_after>﻿using System;
using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace SocketLib {
    
    public class Client : IDisposable {

        public delegate void OnDisconnectHandler();

        public event OnDisconnectHandler OnDisconnect;
        
        public delegate void OnMessageHandler(string message);

        public event OnMessageHandler OnMessage;
        
        protected Socket socket;
        protected Task listenTask;
        protected bool running;
        
        public bool debugEnabled { get; protected set; }
        protected StreamWriter debugFile;

        public Client(Socket socket) {
            this.socket = socket;
            socket.ReceiveTimeout = 1000;
            running = true;
            listenTask = new Task(() => {
                Byte[] received = new Byte[512];
                string message = "";
                
                while (running) {
                    if (socket.Available > 0) {
                        while (socket.Available > 0) {
                            int bytes = socket.Receive(received, received.Length, 0);
                            message += Encoding.ASCII.GetString(received, 0, bytes);
                        }

                        if (message.Length != 0) {
                            if (OnMessage != null) OnMessage(message);

                            if (debugEnabled)
                                debugFile.WriteLine(DateTime.Now.ToShortTimeString() + " -- RECEIVED -- " + message);
                            
{'fraction_non_alphanumeric': 0.07773851590106007, 'fraction_numerical': 0.007388371345968519, 'mean_word_length': 1.4951923076923077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1158433', 'n_tokens_mistral': 744, 'n_tokens_neox': 688, 'n_words': 199}