Skip to content

Commit

Permalink
Cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepPork committed Mar 17, 2023
1 parent 97bcaf3 commit 158e216
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 158e216

Please sign in to comment.