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

main
KKlochko 1 year ago
parent 162f4bd30d
commit fe00d09a64

@ -36,8 +36,12 @@ class ProducerClient:
self.writer = None self.writer = None
async def connect(self): async def connect(self):
try:
self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port) 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}).') 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): async def send(self, message: str):
self.writer.write(struct.pack('<L', len(message))) self.writer.write(struct.pack('<L', len(message)))

Loading…
Cancel
Save