From 3367af481dc7941d5f59b42eae346d233aeafa7f Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 12 Dec 2023 18:54:47 +0200 Subject: [PATCH] Add the error if the client could not connect to the server. --- notification_client/client.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/notification_client/client.py b/notification_client/client.py index 755b4c4..9b7ded8 100644 --- a/notification_client/client.py +++ b/notification_client/client.py @@ -19,6 +19,8 @@ import asyncio import struct +import sys + from notification_client.MessagePrinter import MessagePrinter from notification_client.notitication import Notification @@ -31,7 +33,12 @@ class Client: self.__port = port async def connect(self): - reader, writer = await asyncio.open_connection(self.__ip, self.__port) + try: + reader, writer = await asyncio.open_connection(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) + await self.handle(reader, writer) @staticmethod