diff --git a/app.py b/app.py index 2144b6f..74e7819 100644 --- a/app.py +++ b/app.py @@ -21,6 +21,7 @@ def main(): server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) server.bind((BIND_IP, BIND_PORT)) server.listen(5) @@ -225,11 +226,9 @@ def calculate_crc(request: bytes) -> str: def calculate_message_length(request: bytes) -> str: message = get_message_contents_with_id(request) - lenght=pass_hexadecimal(len(message)) - return f'{lenght.zfill(4)}' + hex_length = hex(len(message)).split('x')[1] -def pass_hexadecimal(decimal: str): - return hex(decimal).split('x')[1] + return hex_length.zfill(4) def generate_timestamp() -> str: diff --git a/test.py b/test.py index 635fff7..75948bc 100644 --- a/test.py +++ b/test.py @@ -6,14 +6,13 @@ load_dotenv(find_dotenv()) -BIND_IP = os.getenv('BIND_IP') BIND_PORT = int(os.getenv('BIND_PORT')) # create an ipv4 (AF_INET) socket object using the tcp protocol (SOCK_STREAM) client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # connect the client -client.connect((BIND_IP, BIND_PORT)) +client.connect(('127.0.0.1', BIND_PORT)) ex_data = [ b'\n9EC40027"ADM-CID"0001L0#1002[#1002|1602 00 001]\r',