snapview / tokio-tungstenite

Future-based Tungstenite for Tokio. Lightweight stream-based WebSocket implementation
MIT License
1.88k stars 236 forks source link

How to correctly handle large messages #328

Closed fenhl closed 6 months ago

fenhl commented 6 months ago

I'm using this library to implement a pair of programs sending and receiving binary messages, which are mostly <1KB but can occasionally be >16MB. Currently this results in an error like Capacity(MessageTooLong { size: 19073409, max_size: 16777216 }) on the receiving end. Of course I could split this data into multiple messages, but I'm wondering if it's possible to configure tokio-tungstenite to handle this, so it still looks like a single message to my code?

daniel-abramov commented 6 months ago

We have a config that you can use to configure the maximum size of the message or frame.

Of course I could split this data into multiple messages, but I'm wondering if it's possible to configure tokio-tungstenite to handle this, so it still looks like a single message to my code?

No, and there are no plans to introduce such behavior, as this is a layer of an application-specific logic (we can't decide how to group/encode messages together into subgroups nor communicate to the other peer about the rules of assembling/interpreting our split as such things are purely application-specific logic and may differ significantly depending on a use case).