import socket
import threading

from database.utils import enter_to_continue

#TODO secure the connection. Maybe SSL tunneling

class Client:
    """Start Client"""
    def __init__(self, host, port):
        self.client = socket.socket()
        self.host = host
        self.port = port
        self.client.connect((self.host, self.port))
    
    def start_conn(self):
        self.client.connect((self.host, self.port))

    def close_conn(self):
        self.client.close()
    
    def send_string(self, code_num, msg):
        """Send short strings\n
        101 - New User\n
        102 - Login\n
        105 - Checkout\n
        111 - Get Daily Menu\n
        112 - Get File\n
        120 - Send File\n
        180 - Close Server"""
        self.client.send(f"{code_num}_{msg}".encode())
    
    def send_file(self, filename, BUFF_LENGTH):
        """Read the file at chunks at a time"""
        out_file = open(filename,"rb")
        file_bytes = out_file.read(1024) 
        while file_bytes != b'':
            self.client.send(file_bytes)
            file_bytes = out_file.read(1024) # read next block from file
        self.client.send(b'')
    
    def recv_file(self, filename, BUFF_LENGTH):
        in_file = open(filename,"wb")
        file_bytes = b''
        while True:
            file_bytes += self.client.recv(BUFF_LENGTH)
            if len(file_bytes) > 0:
                break
        in_file.write(file_bytes)
    
    def recv_string(self, BUFF_LENGTH):
        msg = self.client.recv(BUFF_LENGTH).decode()
        if len(msg) == 0:
            msg = -1
        return msg
e1e372c785b2f9a6fa08cbe9e69d818d7f9f704a
<mask token>


class Client:
    <mask token>

    def __init__(self, host, port):
        self.client = socket.socket()
        self.host = host
        self.port = port
        self.client.connect((self.host, self.port))
    <mask token>
    <mask token>

    def send_string(self, code_num, msg):
        """Send short strings

        101 - New User

        102 - Login

        105 - Checkout

        111 - Get Daily Menu

        112 - Get File

        120 - Send File

        180 - Close Server"""
        self.client.send(f'{code_num}_{msg}'.encode())
    <mask token>
    <mask token>

    def recv_string(self, BUFF_LENGTH):
        msg = self.client.recv(BUFF_LENGTH).decode()
        if len(msg) == 0:
            msg = -1
        return msg

<mask token>


class Client:
    <mask token>

    def __init__(self, host, port):
        self.client = socket.socket()
        self.host = host
        self.port = port
        self.client.connect((self.host, self.port))

    def start_conn(self):
        self.client.connect((self.host, self.port))

    def close_conn(self):
        self.client.close()

    def send_string(self, code_num, msg):
        """Send short strings

        101 - New User

        102 - Login

        105 - Checkout

        111 - Get Daily Menu

        112 - Get File

        120 - Send File

        180 - Close Server"""
        self.client.send(f'{code_num}_{msg}'.encode())

    def send_file(self, filename, BUFF_LENGTH):
        """Read the file at chunks at a time"""
        out_file = open(filename, 'rb')
        file_bytes = out_file.read(1024)
        while file_bytes != b'':
            self.client.send(file_bytes)
            file_bytes = out_file.read(1024)
        self.client.send(b'')
    <mask token>

    def recv_string(self, BUFF_LENGTH):
        msg = self.client.recv(BUFF_LENGTH).decode()
        if len(msg) == 0:
            msg = -1
        return msg

<mask token>


class Client:
    """Start Client"""

    def __init__(self, host, port):
        self.client = socket.socket()
        self.host = host
        self.port = port
        self.client.connect((self.host, self.port))

    def start_conn(self):
        self.client.connect((self.host, self.port))

    def close_conn(self):
        self.client.close()

    def send_string(self, code_num, msg):
        """Send short strings

        101 - New User

        102 - Login

        105 - Checkout

        111 - Get Daily Menu

        112 - Get File

        120 - Send File

        180 - Close Server"""
        self.client.send(f'{code_num}_{msg}'.encode())

    def send_file(self, filename, BUFF_LENGTH):
        """Read the file at chunks at a time"""
        out_file = open(filename, 'rb')
        file_bytes = out_file.read(1024)
        while file_bytes != b'':
            self.client.send(file_bytes)
            file_bytes = out_file.read(1024)
        self.client.send(b'')

    def recv_file(self, filename, BUFF_LENGTH):
        in_file = open(filename, 'wb')
        file_bytes = b''
        while True:
            file_bytes += self.client.recv(BUFF_LENGTH)
            if len(file_bytes) > 0:
                break
        in_file.write(file_bytes)

    def recv_string(self, BUFF_LENGTH):
        msg = self.client.recv(BUFF_LENGTH).decode()
        if len(msg) == 0:
            msg = -1
        return msg

import socket
import threading
from database.utils import enter_to_continue


class Client:
    """Start Client"""

    def __init__(self, host, port):
        self.client = socket.socket()
        self.host = host
        self.port = port
        self.client.connect((self.host, self.port))

    def start_conn(self):
        self.client.connect((self.host, self.port))

    def close_conn(self):
        self.client.close()

    def send_string(self, code_num, msg):
        """Send short strings

        101 - New User

        102 - Login

        105 - Checkout

        111 - Get Daily Menu

        112 - Get File

        120 - Send File

        180 - Close Server"""
        self.client.send(f'{code_num}_{msg}'.encode())

    def send_file(self, filename, BUFF_LENGTH):
        """Read the file at chunks at a time"""
        out_file = open(filename, 'rb')
        file_bytes = out_file.read(1024)
        while file_bytes != b'':
            self.client.send(file_bytes)
            file_bytes = out_file.read(1024)
        self.client.send(b'')

    def recv_file(self, filename, BUFF_LENGTH):
        in_file = open(filename, 'wb')
        file_bytes = b''
        while True:
            file_bytes += self.client.recv(BUFF_LENGTH)
            if len(file_bytes) > 0:
                break
        in_file.write(file_bytes)

    def recv_string(self, BUFF_LENGTH):
        msg = self.client.recv(BUFF_LENGTH).decode()
        if len(msg) == 0:
            msg = -1
        return msg

import socket
import threading

from database.utils import enter_to_continue

#TODO secure the connection. Maybe SSL tunneling

class Client:
    """Start Client"""
    def __init__(self, host, port):
        self.client = socket.socket()
        self.host = host
        self.port = port
        self.client.connect((self.host, self.port))
    
    def start_conn(self):
        self.client.connect((self.host, self.port))

    def close_conn(self):
        self.client.close()
    
    def send_string(self, code_num, msg):
        """Send short strings\n
        101 - New User\n
        102 - Login\n
        105 - Checkout\n
        111 - Get Daily Menu\n
        112 - Get File\n
        120 - Send File\n
        180 - Close Server"""
        self.client.send(f"{code_num}_{msg}".encode())
    
    def send_file(self, filename, BUFF_LENGTH):
        """Read the file at chunks at a time"""
        out_file = open(filename,"rb")
        file_bytes = out_file.read(1024) 
        while file_bytes != b'':
            self.client.send(file_bytes)
            file_bytes = out_file.read(1024) # read next block from file
        self.client.send(b'')
    
    def recv_file(self, filename, BUFF_LENGTH):
        in_file = open(filename,"wb")
        file_bytes = b''
        while True:
            file_bytes += self.client.recv(BUFF_LENGTH)
            if len(file_bytes) > 0:
                break
        in_file.write(file_bytes)
    
    def recv_string(self, BUFF_LENGTH):
        msg = self.client.recv(BUFF_LENGTH).decode()
        if len(msg) == 0:
            msg = -1
        return msg