|
|
|
@ -46,8 +46,8 @@ class Server:
|
|
|
|
|
self.__ip, self.__producer_port
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.console.print(f'Serves on {self.__ip}:{self.__port} for clients.')
|
|
|
|
|
self.console.print(f'Receives notifications from producers at {self.__ip}:{self.__producer_port}.')
|
|
|
|
|
self.console.print(f'[yellow b][INFO][/] Serves on {self.__ip}:{self.__port} for clients.')
|
|
|
|
|
self.console.print(f'[yellow b][INFO][/] Receives notifications from producers at {self.__ip}:{self.__producer_port}.')
|
|
|
|
|
|
|
|
|
|
async with self.__producer_socket, self.__client_socket:
|
|
|
|
|
await asyncio.gather(
|
|
|
|
@ -72,7 +72,7 @@ class Server:
|
|
|
|
|
|
|
|
|
|
async def handle_producer(self, reader, writer, notification_dir):
|
|
|
|
|
addr = writer.get_extra_info('peername')
|
|
|
|
|
self.console.print(f"A producer ({addr}) connected.")
|
|
|
|
|
self.console.print(f"[yellow b][INFO][/] A producer ({addr[0]}:{addr[1]}) connected.")
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
while True:
|
|
|
|
@ -80,7 +80,7 @@ class Server:
|
|
|
|
|
message = await self.receive_message(reader)
|
|
|
|
|
|
|
|
|
|
if title == '' and message == '':
|
|
|
|
|
self.console.print(f"The producer ({addr[0]}:{addr[1]}) finished.")
|
|
|
|
|
self.console.print(f"[yellow b][INFO][/] The producer ({addr[0]}:{addr[1]}) finished.")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
await self.broadcast_message(title)
|
|
|
|
@ -89,12 +89,12 @@ class Server:
|
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
|
pass
|
|
|
|
|
finally:
|
|
|
|
|
self.console.print(f"The producer ({addr}) disconnected.")
|
|
|
|
|
self.console.print(f"[yellow b][INFO][/] The producer ({addr[0]}:{addr[1]}) disconnected.")
|
|
|
|
|
writer.close()
|
|
|
|
|
|
|
|
|
|
async def handle_client(self, reader, writer):
|
|
|
|
|
addr = writer.get_extra_info('peername')
|
|
|
|
|
self.console.print(f"A client ({addr}) connected.")
|
|
|
|
|
self.console.print(f"[yellow b][INFO][/] A client ({addr[0]}:{addr[1]}) connected.")
|
|
|
|
|
self.__client_writers.append(writer)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
@ -105,7 +105,7 @@ class Server:
|
|
|
|
|
except asyncio.CancelledError:
|
|
|
|
|
pass
|
|
|
|
|
finally:
|
|
|
|
|
self.console.print(f"The client ({addr}) disconnected.")
|
|
|
|
|
self.console.print(f"[yellow b][INFO][/] The client ({addr[0]}:{addr[1]}) disconnected.")
|
|
|
|
|
self.__client_writers.remove(writer)
|
|
|
|
|
writer.close()
|
|
|
|
|
|
|
|
|
|