0

I'd like to stream data over a WebSocket connection using Yaws. I've read the Yaws documentation about Streaming Data and Web Sockets, and I found the Yaws API functions below that seem relevant:

yaws_api:websocket_send(Pid, {text, <<"hi there!">>}).

yaws_api:stream_chunk_deliver(YawsPid, BinData).

yaws_api:stream_chunk_end(YawsPid).

But it's not clear how they're related, or even if they're related. Can anyone explain how to stream multiple chunks of data over a Yaws websocket connection such that the receiver sees all the chunks as one fragmented message?

Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46

1 Answers1

0

Yaws streaming is focused on applications that send HTTP responses that have an unknown content length at the time of sending the response headers, and so want to use HTTP chunking, or applications that want to avoid buffering all response content or use Comet-style replies. WebSocket doesn't have the same restrictions around sending data, though, so streaming requires using yaws_api:websocket_send/2 with the #ws_frame{} record type fin field set to false for each chunk of the stream until the final chunk where it must be true. You can find Yaws websocket examples in the Yaws source code examples directory that might help.

Community
  • 1
  • 1
Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46