Add the error if the client could not connect to the server.

main
KKlochko 1 year ago
parent cc5148cee5
commit 3367af481d

@ -19,6 +19,8 @@
import asyncio import asyncio
import struct import struct
import sys
from notification_client.MessagePrinter import MessagePrinter from notification_client.MessagePrinter import MessagePrinter
from notification_client.notitication import Notification from notification_client.notitication import Notification
@ -31,7 +33,12 @@ class Client:
self.__port = port self.__port = port
async def connect(self): async def connect(self):
try:
reader, writer = await asyncio.open_connection(self.__ip, self.__port) 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) await self.handle(reader, writer)
@staticmethod @staticmethod

Loading…
Cancel
Save