snapview / tokio-tungstenite

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

WebSocketStream<TlsStream<TcpStream>> and Framed #260

Closed hanusek closed 1 year ago

hanusek commented 1 year ago

Hello @snapview I would like to create - Framed<WebSocketStream<TlsStream>, BytesCodec>.

How to use WebSocketStream<TlsStream<TcpStream>> and Framed?

daniel-abramov commented 1 year ago

We have an open (albeit old) issue about that: https://github.com/snapview/tokio-tungstenite/issues/32

It is not possible to use Framed out-of-the-box, but it's possible to build such support by extracting certain bits out of tungstenite and implementing the Encoder and Decoder traits.

The main reason for this is that Framed does not have a complicated state machine, it's more about encoding/decoding things. Whereas with tungstenite we also manage the state machine that complies with the RFC.

If we were to extract the tungstenite's part of the message parsing in its own tungstenite-core, then building Framed on top of that would be quite trivial.