|
|
@ -23,6 +23,7 @@ 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
|
|
|
|
|
|
|
|
from notification_client.timestamp import Timestamp
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Client:
|
|
|
|
class Client:
|
|
|
@ -35,9 +36,10 @@ class Client:
|
|
|
|
async def connect(self):
|
|
|
|
async def connect(self):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
reader, writer = await asyncio.open_connection(self.__ip, self.__port)
|
|
|
|
reader, writer = await asyncio.open_connection(self.__ip, self.__port)
|
|
|
|
MessagePrinter.connected(self.__ip, self.__port)
|
|
|
|
MessagePrinter.connected(self.__ip, self.__port, Timestamp.now())
|
|
|
|
except ConnectionRefusedError:
|
|
|
|
except ConnectionRefusedError:
|
|
|
|
sys.stderr.write("Could not connect to the server. Please, check the ip and the port.\n")
|
|
|
|
now = Timestamp.now()
|
|
|
|
|
|
|
|
sys.stderr.write(f"[ERROR][{now}] Could not connect to the server. Please, check the ip and the port.\n")
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
|
|
|
await self.handle(reader, writer)
|
|
|
|
await self.handle(reader, writer)
|
|
|
@ -54,6 +56,8 @@ class Client:
|
|
|
|
title = await self.receive_message(reader)
|
|
|
|
title = await self.receive_message(reader)
|
|
|
|
message = await self.receive_message(reader)
|
|
|
|
message = await self.receive_message(reader)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
now = Timestamp.now()
|
|
|
|
|
|
|
|
MessagePrinter.printInfo('A notification received from the server.', now)
|
|
|
|
MessagePrinter.print(title, message)
|
|
|
|
MessagePrinter.print(title, message)
|
|
|
|
|
|
|
|
|
|
|
|
Notification.notify(title, message)
|
|
|
|
Notification.notify(title, message)
|
|
|
|