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