Skip to content

Conversation

@michalpokusa
Copy link
Contributor

@michalpokusa michalpokusa commented Jan 13, 2026

⭐ Added:

  • Support for websocket communication with CONT frames/fragmented messages
  • Several condition checks that indicate protocol error in websocket communication

🪛Fixes:

🛠️ Updated/Changed:

  • Mainly Websocket.receive() and Websocket._handle_frame() to work with fragmented messages
  • Websocket._buffer was refactored to be initialized once and reused, instead of inside every ._read_frame() call

Before merge, I would appreciate anyones input on these topics:

  • I decided to use monotonic_ns because it should not lose precision after multiple hours, is it correct to assume that any microcontroller that would be able to support Websockets will also be able to support long ints required for ns precision?
  • In current implementation if a message is split into multiple frames, the server/websocket will NOT block in .receive() until a message is completed, it will append received payload and hold it over maybe even multiple .receive() calls until it is complete, and only then will return it, I believe it is a more asynchronous approach than blocking, but I would like to gather feedback on that.

Any testing and feedback would be appreciated.

@dhalbert
Copy link
Contributor

  • I decided to use monotonic_ns because it should not lose precision after multiple hours, is it correct to assume that any microcontroller that would be able to support Websockets will also be able to support long ints required for ns precision?

Yes, only the absolute smallest ports don't support long ints (mostly the SAMD21 ports without an external flash chip).

@michalpokusa michalpokusa marked this pull request as ready for review January 15, 2026 18:07
@michalpokusa michalpokusa changed the title WIP: Support for Websocket CONT frames/fragmented messages Support for Websocket CONT frames/fragmented messages Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TimeoutError in CPython example starting from 3.10 Ping requests pollute websocket receive streams

2 participants