Verified Commit 2bb03f84 authored by Jakob Moser's avatar Jakob Moser
Browse files

Add more logging to Client

parent ced78ef9
Loading
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
import json
import logging
from collections.abc import Callable
from dataclasses import dataclass
from pathlib import Path
@@ -19,14 +20,21 @@ class Client:
        socket = Socket(AF_UNIX, SOCK_STREAM)

        try:
            logging.debug("Connecting to socket")
            socket.connect(str(self.socket_path.resolve()))
            logging.debug("Sending packet")
            socket.sendall((json.dumps(packet) + "\n").encode("utf-8"))
            logging.debug("Packet sent")

            # TODO What if the response is longer than 1024 bytes?
            logging.debug("Receiving response")
            response = socket.recv(1024)
            logging.debug("Response received")
            return json.loads(response.decode("utf-8"))
        finally:
            logging.debug("Closing socket")
            socket.close()
            logging.debug("Socket closed")

    def on_receive_push(self, handle_packet: Callable[[Packet], None]) -> None:
        """