curl-library
Re: Server-sent events with libcurl
Date: Tue, 28 Dec 2010 10:44:45 -0500
On Tue, Dec 28, 2010 at 10:28 AM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Tue, 28 Dec 2010, amit paliwal wrote:
>
> Reply: thanks Daniel, i agree to what you are saying, but my point is
>> simple, and in fact it is my question that if SSE is supported it means
>> server can push events any time, right?
>>
>
> Not exactly.
>
> A server can only send an event while the client is waiting for the event,
> and it is only waiting for the event when it has sent a request and the
> connection is still alive.
Reply: I meant it Daniel, the connection will be alive and the client will
be blocked to get some data on that connection.
>
>
> 1) Client will initially send HTTP GET and get the response from the
>> server
>> and then it will be having persistent connection with Server.
>> 2) Server can push events at any time, and the Client shoul;d be able to
>> receive those events on top of HTTP as payload.
>>
>
> Yes.
>
>
> 3) client should be able to reply.
>>
>
> No. The messages are one-way from the server from what I understand. It is
> an HTTP response after all.
Reply: Server will send SSE on top of HTTP response message and the Client
will parse that SSE and from there I need to reply to the server, for e.g.
some status code like event received properly. This reply need to be sent in
HTTP GET message, so one particular scenario is receiving the HTTP response
message for SSe and sending reply of SSE in HTTP GET. . I agree that this
looks kind of opposite, but this is really what I need to implement and I
need your input whether it can be achieved by libcurl or not? Do I need to
tweak the code of the library for my custom use?
>
>
> Client will keep the connection open and my only concern is in knowing
>> that will Client be able to receive SSE on that socket connection and send
>> response by using libcurl.
>>
>
> Yes, as SSE is plain HTTP it will work fine!
>
> libcurl offers both blocking and non-blocking interfaces and you can
>>> decide which one is best suited for your application. When the write
>>> callback has got enough data to construct a single SSE message you can fire
>>> it off.
>>>
>>
>> Client will not send SSE, SSE will be received by Client and we need to
>> parse it.
>>
>
> Exactly: "When the write callback has got enough data to construct a single
> SSE message you can fire it off." And by "fire it off" I meant parse it,
> consider it, take care of it or whatever you need to do with the SSE when it
> has arrived at the client.
Reply: when I was working i was able to parse the received data but after
that I was not able to send the data back to server, I wanted to construct
some payload and send it on top of HTTP GET. I was stuck as how to ask
libcurl to pick up payload from my function and send HTTP GET.
>
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-12-28