diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3a803..01a9d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p ## [Unreleased] +- Added TCPDispatchClient to tcp_client - Fixed TPC dispatcher type annotations ## [1.9.3] diff --git a/pythonosc/tcp_client.py b/pythonosc/tcp_client.py index 512b666..4ca622c 100644 --- a/pythonosc/tcp_client.py +++ b/pythonosc/tcp_client.py @@ -122,6 +122,25 @@ def get_messages(self, timeout: int = 30) -> Generator: r = self.receive(timeout) +class TCPDispatchClient(SimpleTCPClient): + """OSC TCP Client that includes a :class:`Dispatcher` for handling responses and other messages from the server""" + + dispatcher = Dispatcher() + + def handle_messages(self, timeout_sec: int = 30) -> None: + """Wait :int:`timeout` seconds for a message from the server and process each message with the registered + handlers. Continue until a timeout occurs. + + Args: + timeout: Time in seconds to wait for a message + """ + r = self.receive(timeout_sec) + while r: + for m in r: + self.dispatcher.call_handlers_for_packet(m, (self.address, self.port)) + r = self.receive(timeout_sec) + + class AsyncTCPClient: """Async OSC client to send :class:`OscMessage` or :class:`OscBundle` via TCP"""