From bf674eb61c86db565fa70df37f85fe3cbe189943 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 12 Dec 2023 15:42:36 +0200 Subject: [PATCH] Add the producer and the entry point. --- notification_producer/main.py | 12 +++++++ notification_producer/producer_client.py | 45 ++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 notification_producer/main.py create mode 100644 notification_producer/producer_client.py diff --git a/notification_producer/main.py b/notification_producer/main.py new file mode 100644 index 0000000..65a49a0 --- /dev/null +++ b/notification_producer/main.py @@ -0,0 +1,12 @@ +import asyncio +from .producer_client import ProducerClient + + +def main(): + client = ProducerClient('127.0.0.1', 5554) + asyncio.run(client.notify_interactive()) + + +if __name__ == '__main__': + main() + diff --git a/notification_producer/producer_client.py b/notification_producer/producer_client.py new file mode 100644 index 0000000..6395c90 --- /dev/null +++ b/notification_producer/producer_client.py @@ -0,0 +1,45 @@ +import asyncio +import struct +import sys + + +class ProducerClient: + BUFFER_SIZE = 1024 + + def __init__(self, ip: str, port: int): + self.__ip = ip + self.__port = port + self.reader = None + self.writer = None + + async def connect(self): + self.reader, self.writer = await asyncio.open_connection(self.__ip, self.__port) + + async def send(self, message: str): + self.writer.write(struct.pack('