diff --git a/networking/Networking.py b/networking/Networking.py index 1ae64d8..79c3047 100644 --- a/networking/Networking.py +++ b/networking/Networking.py @@ -9,13 +9,19 @@ class Networking: def __init__(self, output_server_address, input_socket_address): self.retries = 0 self.server_address = "" + self.output_server_address = output_server_address + self.input_socket_address = input_socket_address + self.__connect__(output_server_address, input_socket_address) + + + def __connect__(self): self.input_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.output_session = req.Session() adapter = req.adapters.UnixAdapter(pool_connections=1) self.output_session.mount('http+unix://', adapter) - self.server_address = "http+unix://" + output_server_address.replace("/", "%2F") - self.input_socket.connect(input_socket_address) - print("Connected to " + input_socket_address + " and started server " + self.server_address) + self.server_address = "http+unix://" + self.output_server_address.replace("/", "%2F") + self.input_socket.connect(self.input_socket_address) + print("Connected to " + self.input_socket_address + " and started server " + self.server_address) def get(self, path): if self.retries > config.MAX_NETWORK_RETRIES: @@ -24,10 +30,11 @@ class Networking: try: response = self.output_session.get(self.server_address + path) except Exception as e: - logging.error("Network exception. Could not get " + path) + logging.error("Network exception. Could not get " + path + ".... Reconnecting!") logging.error(e) self.retries += 1 sleep(config.NETWORK_SLEEP_TIME_SECONDS) + self.__connect__() return self.get(path) assert response.status_code == 200