Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streaming version of send #119

Open
sanketr opened this issue Jun 16, 2016 · 4 comments
Open

Streaming version of send #119

sanketr opened this issue Jun 16, 2016 · 4 comments

Comments

@sanketr
Copy link

sanketr commented Jun 16, 2016

It seems that the library doesn't have a streaming version for building websocket message. Here is the send code from the library:

 send :: Connection -> Message -> IO ()
    send conn msg = do
        case msg of
            (ControlMessage (Close _ _)) ->
                writeIORef (connectionSentClose conn) True
            _ -> return ()
        connectionWrite conn msg

Since we can call connectionWrite only once when sending the message, it seems all of the data must be accumulated in memory to build the message. So, the lazy bytestring is not very useful because we must accumulate it all for the message.

Is it trivial to build a streaming version of send on top of Websockets library (basically, be able to call write multiple times) ? Then, we could connect it with conduit, pipes or streaming.

It seems receive is streaming because it has lazy bytestring. But, send isn't despite lazy bytestring. Please correct me if I got this wrong.

My use case is receiving and sending large objects through websocket server (an API server which is just an intermediary between the client and storage). I could do chunking through multiple messages, and then sending close code to indicate whether it is finished or not. But, it seems cleaner to build a single message in streaming fashion rather than building another streaming protocol on top of websocket messages.

@jaspervdj
Copy link
Owner

I agree, a streaming version would be very nice. I also think it would not be extremely hard to add. We would mainly need to patch Network.WebSockets.Hybi13.encodeFrame so that it produces multiple frames for large lazy Bytestrings, and avoids calling BL.length (which is where it is currently fully evaluated).

@LeanderK
Copy link

LeanderK commented Dec 18, 2016

i have a use-case where i need to just push the input from an IPC socket into an web socket, is this issue an deal breaker for this? It has to be somewhat performant (the workload for one connection is comparable to streaming video and it would have to handle multiple). I would guess just choosing smaller bytestrings could solve the problem.

@jaspervdj
Copy link
Owner

@LeanderK Yes, just splitting them up in multiple messages would do the trick.

@tolysz
Copy link

tolysz commented Jan 4, 2017

I was thinking about it, maybe if we put it in a new module with "Lazy" in the name :)

supersven added a commit to wireapp/wire-server that referenced this issue Feb 3, 2022
The websockets library does not support streaming
(jaspervdj/websockets#119). So, there is no
value in superficially transforming data to a stream that later won't be
streamed. However, WebSocketsData enables us to be polymorphic in
the message type, i.e. let the endpoints type decide what to use. This
would make streaming easier to enable (if it's ever implemented by the
library) and safes us from some nasty conversion code.
supersven added a commit to wireapp/wire-server that referenced this issue Feb 4, 2022
The websockets library does not support streaming
(jaspervdj/websockets#119). So, there is no
value in superficially transforming data to a stream that later won't be
streamed. However, WebSocketsData enables us to be polymorphic in
the message type, i.e. let the endpoints type decide what to use. This
would make streaming easier to enable (if it's ever implemented by the
library) and safes us from some nasty conversion code.
supersven added a commit to wireapp/wire-server that referenced this issue Feb 4, 2022
* Single notification pushes are strict in their HTTP body

The websockets library does not support streaming
(jaspervdj/websockets#119). So, there is no
value in superficially transforming data to a stream that later won't be
streamed. However, WebSocketsData enables us to be polymorphic in
the message type, i.e. let the endpoints type decide what to use. This
would make streaming easier to enable (if it's ever implemented by the
library) and safes us from some nasty conversion code.

* Forward the pushed notification as is

This reflects the prior behavior of Cannon (that should not change).
The type RawJson represents json content as plain text.
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

No branches or pull requests

4 participants