Skip to content

Is cpprestsdk supports SSE #838

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

Open
vivbang opened this issue Aug 16, 2018 · 7 comments
Open

Is cpprestsdk supports SSE #838

vivbang opened this issue Aug 16, 2018 · 7 comments

Comments

@vivbang
Copy link

vivbang commented Aug 16, 2018

Is cpprestsdk supports SSE. If no, then any plan to add support in future.
We are planning to use it for chat like application where on data from client can be broadcast to all connected client using SSE.
Can this be accomplish with current SDK.

@BillyONeal
Copy link
Member

What is SSE?

@vivbang
Copy link
Author

vivbang commented Oct 23, 2018

SSE is Server Sent Event.
Please refer (https://www.w3.org/TR/eventsource/) for more detail.

@BillyONeal
Copy link
Member

No plans to do anything like that at present.

@vivbang
Copy link
Author

vivbang commented Oct 23, 2018

Hi ... I was able to implement Server Sent Event(SSE) using proposed solution in Issue 11.
Link: #11

Code Snippet:
streams::producer_consumer_buffer rwbuf;

streams::basic_istream<uint8_t> stream(rwbuf);
response.set_body(stream); // response is http response

auto rep = request.reply(response);

rwbuf.putn_nocopy("data", length).wait();
rwbuf.putn_nocopy("data2", length2).wait();
rwbuf.sync().wait();
rwbuf.putn_nocopy("data3", length).wait();
rwbuf.close(std::ios_base::out).wait();
rep.wait();

We can now keep writing on buffer whenever there is data, and calling "rwbuf.sync().wait();" will flush all data to http connection. I am able to receive data on client side. Connection will close from server only when we call "rwbuf.close(std::ios_base::out).wait();"

It is possible that http connection can be closed from client side , in that case how to determine on server side whether underlying connection is still active before writing on buffer.

Can you please suggest a way to determine whether underlying http connection is still open or not before writing in buffer.

I have tried to see the producer_consumer_buffer and basic_istream class members, but did not get any parameter, function which can be used to determine the connection status.

@BillyONeal
Copy link
Member

Can you please suggest a way to determine whether underlying http connection is still open or not before writing in buffer.

Write to the buffer and deal with the consequences of failure. Just because the connection exists before you try to do that write doesn't mean it exists halfway through your send attempt.

(Having only just inherited ownership of Cpprestsdk myself I'm not really sure of the best way to achieve what you're looking to do)

@vivbang
Copy link
Author

vivbang commented Oct 24, 2018

Thanks BillyONeal for your time.
I need one help. I need to know which code/file name handles sending http data to underlying TCP connection on server side. Any suggestion would be helpful.

@BillyONeal
Copy link
Member

That code is not in Cpprestsdk. For the WinHTTP backend, we delegate to WinHTTP, for the WinRT backend, we delegate to WinRT, and for the asio backend, we delegate to asio. This is a platform abstraction layer and an asynchronous programming tech demo from several years ago, not a full HTTP stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants