Skip to content

Streaming version of send #119

Open
Open
@sanketr

Description

@sanketr

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions