diff --git a/notification_producer/producer_client.py b/notification_producer/producer_client.py index f06cc30..f0623c8 100644 --- a/notification_producer/producer_client.py +++ b/notification_producer/producer_client.py @@ -36,8 +36,12 @@ class ProducerClient: self.writer = None async def connect(self): - self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port) - self.console.print(f'[yellow b][INFO][/] Connected to the server ({self.__ip}:{self.__port}).') + try: + self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port) + self.console.print(f'[yellow b][INFO][/] Connected to the server ({self.__ip}:{self.__port}).') + except ConnectionRefusedError: + sys.stderr.write("Could not connect to the server. Please, check the ip and the port.\n") + sys.exit(1) async def send(self, message: str): self.writer.write(struct.pack('