Skip to content

Commit 5a89a7a

Browse files
committed
adding TCPDispatchClient Class
1 parent edcec23 commit 5a89a7a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pythonosc/tcp_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,25 @@ def get_messages(self, timeout: int = 30) -> Generator:
121121
yield OscMessage(m)
122122
r = self.receive(timeout)
123123

124+
class TCPDispatchClient(SimpleTCPClient):
125+
"""OSC Client that includes a :class:`Dispatcher` for handling responses and other messages from the server"""
126+
127+
dispatcher = Dispatcher()
128+
129+
def handle_messages(self, timeout: int = 30) -> None:
130+
"""Wait :int:`timeout` seconds for a message from the server and process each message with the registered
131+
handlers. Continue until a timeout occurs.
132+
133+
Args:
134+
timeout: Time in seconds to wait for a message
135+
"""
136+
r = self.receive(timeout)
137+
while r:
138+
for m in r:
139+
self.dispatcher.call_handlers_for_packet(m, (self.address, self.port))
140+
r = self.receive(timeout)
141+
142+
124143

125144
class AsyncTCPClient:
126145
"""Async OSC client to send :class:`OscMessage` or :class:`OscBundle` via TCP"""

0 commit comments

Comments
 (0)