<commit_before>require 'gserver'
require 'json'

module XRefreshServer

    # server
    class Server < GServer
        attr_accessor :clients

        def initialize(port, host, max_connections, *args)
            super
            @clients = Set.new
            @last_client_id = 0
            OUT.puts "#{green('Started server')} on #{blue("#{host}:#{port}")} (max #{max_connections} clients)"
        end

        def serve(socket)
            socket.binmode
            @last_client_id += 1
            client = Client.new(@last_client_id, socket)
            @clients.add(client)
            loop do
                begin
                    buffer = socket.gets(XREFRESH_MESSAGE_SEPARATOR)
                rescue
                    # socket breaks on client disconnection
                    break
                end
                break unless buffer
                message = buffer[0...-XREFRESH_MESSAGE_SEPARATOR.size]
                OUT.puts "[debug] received: "+ message
                json = JSON.parse(message)<commit_msg>remove forgotten debug message<commit_after>require 'gserver'
require 'json'

module XRefreshServer

    # server
    class Server < GServer
        attr_accessor :clients

        def initialize(port, host, max_connections, *args)
            super
            @clients = Set.new
            @last_client_id = 0
            OUT.puts "#{green('Started server')} on #{blue("#{host}:#{port}")} (max #{max_connections} clients)"
        end

        def serve(socket)
            socket.binmode
            @last_client_id += 1
            client = Client.new(@last_client_id, socket)
            @clients.add(client)
            loop do
                begin
                    buffer = socket.gets(XREFRESH_MESSAGE_SEPARATOR)
                rescue
                    # socket breaks on client disconnection
                    break
                end
                break unless buffer
                message = buffer[0...-XREFRESH_MESSAGE_SEPARATOR.size]
                json = JSON.parse(message)
{'fraction_non_alphanumeric': 0.08455522971652003, 'fraction_numerical': 0.002932551319648094, 'mean_word_length': 1.5460199004975124, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4866068', 'n_tokens_mistral': 550, 'n_tokens_neox': 521, 'n_words': 126}