Project

General

Profile

Does Response Continuation stream or cache-and-then-send data?

Added by Plug Gulp over 3 years ago

I am trying to send stream of periodically and dynamically generated numbers to clients. When using Response Continuation I realised that when a response continuation is created, the data is not sent to client immediately. Instead it is sent when the request handler does not create the response continuation. So is the data cached by Wt when continuation is created and then sent to the client only when the request handler does not create further continuations?

I am trying to use continuation with static resources(REST API). The client at the very beginning posts a request to get the data. The server does not close the connection by creating continuations. This works as the connection is not closed, but the data is not sent to the client unless the request handler stops creating continuation.

How does one achieve streaming periodically and dynamically generated data to client?


Replies (5)

RE: Does Response Continuation stream or cache-and-then-send data? - Added by Emeric Poupon about 3 years ago

Hi!

I use static resources to stream data with continuations, and I don't observe what you describe.
You just have to put data in the output stream, and set the continuation only if you have more.
I guess your handleRequest function will be called again when enough of the previously provided data has been consumed by the client.
Just check if WFileResource behaves as expected?

Or maybe you use waitForMoreData?

RE: Does Response Continuation stream or cache-and-then-send data? - Added by Plug Gulp about 3 years ago

Just check if WFileResource behaves as expected?

For file resource it makes sense as it has finite length. But what happens, say, when data is received periodically over a network?

Or maybe you use waitForMoreData?

For the example I gave above of data received from a network, the request continuation will have to call waitForMoreData to wait for data to be arrived on the network. So, if I call waitForMoreData, then Wt should flush the already available data in its stream to the user. But I don't see that happening. And if I don't call waitForMoreData then the connection to the client will be closed and then the client will have to resend a request to the server. The only way to implement continuous periodic streaming, without the client making another request, is by calling waitForMoreData. Al least that is what I gathered from the documents and the code. If you know of a better way to implement this then please do share. It will help alot.

RE: Does Response Continuation stream or cache-and-then-send data? - Added by Wim Dumon about 3 years ago

Hi Plug,

Does it work if you call flush() on the stream when calling waitForMoreData()?

Wim.

RE: Does Response Continuation stream or cache-and-then-send data? - Added by Korneel Dumon about 3 years ago

Hi,

I did a little test using cURL and the data seems to come through immediately with continuations.
Where are you calling haveMoreData() from? Not sure, but I believe it needs to be from inside the io_service context to work. For a static resource I wonder how you do it, since you can't really call WServer::post.

RE: Does Response Continuation stream or cache-and-then-send data? - Added by Emeric Poupon about 3 years ago

This reminds me this thread: https://redmine.emweb.be/boards/2/topics/16803
This is what I currently do, and AFAIR responses are transmitted with continuations and do not wait for the request to end.

    (1-5/5)