<commit_before># -*- coding: utf-8 -*-
import socket
from sys import argv, stdout, exit
from json import loads
from time import sleep
from time import strftime
from os import system

from threading import Thread

from pprint import pprint

from models import *

class Client:

    stop = False
    
    def __init__(self, host, port):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect((host, port))

    '''
    Her tar vi i mot ting fra serveren.
    '''
    def handle_network(self):
        sender = ''
        while not self.stop:
            self.print_pre(sender)
            res = self.sock.recv(2**20)
            if res == b'':
                self.stop = True
                break

            res_dict = loads(res.decode('utf-8'))
            res = Response(**res_dict)

            if res.response == 'message':
                if res.sender != sender:
                    self.print_response(res)<commit_msg>fikset at klienten ikke mottokk hele historien<commit_after># -*- coding: utf-8 -*-
import socket
from sys import argv, stdout, exit
from json import loads
from time import sleep
from time import strftime
from os import system

from threading import Thread

from pprint import pprint

from models import *

BUFFER_SIZE=1024

class Client:

    stop = False
    
    def __init__(self, host, port):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect((host, port))

    '''
    Her tar vi i mot ting fra serveren.
    '''
    def handle_network(self):
        sender = ''
        while not self.stop:
            self.print_pre(sender)
            res = self.sock.recv(BUFFER_SIZE)
            while len(res) % BUFFER_SIZE == 0: # kanskje hacky?
                sleep(0.2)
                res += self.sock.recv(BUFFER_SIZE)

            if res == b'':
                self.stop = True
                break

            res_dict = loads(res.decode('utf-8'))
            res = Response(**res_dict)

            if res.response == 'message':
                if res.sender != sender:
                    self.print_response(res)
{'fraction_non_alphanumeric': 0.09737827715355805, 'fraction_numerical': 0.006554307116104869, 'mean_word_length': 1.919398907103825, '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': '711134', 'n_tokens_mistral': 633, 'n_tokens_neox': 599, 'n_words': 185}