Re: [Cppcms-users] How to combine SSE with the url dispatcher
Brought to you by:
artyom-beilis
|
From: Marcel H. <ke...@co...> - 2014-02-22 12:02:34
|
On 22.02.2014 11:20, eric middelkoop wrote:
> Hello,
Hi Eric,
> While having all the rest the same as in the ticker example.
>
> I open the page with 127.0.0.1:8080/robot/camerasettings
> <http://127.0.0.1:8080/robot/camerasettings> and the page is displayed
> correctly but the stream keeps loading and is not being displayed. After
> stopping the server, the data is displayed and looks like this:
>
I think you still haven't fully understood the concept of streams. A
stream is a non-ending flow of information.
Therefore your browser cannot display the infos except the stream has
been closed (you stopped the server), because it doesn't know if there
is anything left to display (and it is indeed).
So what you are missing is a html page like the_ticker.html with
javascript inside, that opens the stream and gets the needed
information. I think you should look at 'the_ticker.html' a second time,
especially the javascript part.
>
> void MyApp::cameraSettings()
> {
> string page = FileSystem().readFileIntoString("the_ticker.html");
> stream_->accept(release_context());
> response().out() << page.c_str();
> }
I don't know what you are trying, but it's getting wrong ;)
> So I have two questions:
>
> 1) How do I combine server side events with url dispatching in cppcms? As I would like to create and send the page to the browser from a method and start to stream events after the page has loaded.
Hmmm, you should (if it's possible) let the stream run from the
beginning of your application. That's how it should work. The
dispatching is the same as in every other application. You have a method
that creates a page with response().out() << "foo" or with a template.
It's up to you.
>
> 2) How do I stop the stream if the user switches to another page or does it stop itself?
As I said, you should not.
>
> I can provide full sourcecode if necessary. Sofar I couldn't find other comparable examples.
>
> My guess is that it shouldn't be all that difficult once you know, but currently I do not (-;
>
If you really need to start and stop the stream, I *think* it should
work via [0]. You mount a asynchronous application and as soon the
pointer becomes 'illegal' the application will be dismounted. Maybe you
should look at that, but I think Artyom can help here more than I can.
Maybe he'll clarify this.
Greetings
[0]
http://cppcms.com/cppcms_ref/latest/classcppcms_1_1applications__pool.html#a5df195e454c857c4c064f8593c76fc45
|