Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 19 additions & 0 deletions pythonosc/tcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: int = 30) -> None:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please suffix the arg with the unit, it's not typed so it makes it explicit/easier on the clients to understand.

timeout_sec: int = 30

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, thanks.

"""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)
while r:
for m in r:
self.dispatcher.call_handlers_for_packet(m, (self.address, self.port))
r = self.receive(timeout)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't change r if you're looping over it already

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, bad tab placement, sorry, fixed.



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

Expand Down