Skip to content

Commit f1e3e31

Browse files
authored
Merge pull request #192 from jms5194/main
Adds TCPDispatch client
2 parents 5eb6f7a + 8677a06 commit f1e3e31

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
55

66
## [Unreleased]
77

8+
- Added TCPDispatchClient to tcp_client
89
- Fixed TPC dispatcher type annotations
910

1011
## [1.9.3]

pythonosc/tcp_client.py

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

124124

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

0 commit comments

Comments
 (0)