[Libwebsockets] "Split" HTTP Responses

"Andy Green (林安廸)" andy at warmcat.com
Thu Feb 14 16:35:51 CET 2013


On 14/02/13 22:29, the mail apparently from Drew Noakes included:
> I too would be interested in an example that shows how to formulate a
> non-file response to a web request through libwebsockets. My use case is
> similar -- I'd like a client to be able to request a static dump of some
> data, probably as a JSON document. This would be composed dynamically in
> the same process as my libwebsockets server.

I just pushed an example sending a 2.4MB JPEG "by hand" in the test 
server code... the same scheme works for any kind of data and uses the 
same nonblocking ready-to-send scheme as the websockets does

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=fbf48227b3b00ec091defab379b541d1dc99cbee

-Andy

> On 14 February 2013 13:42, "Andy Green (林安廸)" <andy at warmcat.com
> <mailto:andy at warmcat.com>> wrote:
>
>     On 14/02/13 21:34, the mail apparently from Andreas Wetzel included:
>
>
>         Hi,
>
>         Currently, I'm using libwebsockets v1.1 to stream live
>         sensor-data to a
>         web-interface. the data is accumulated outside of libwebsockets
>         thread,
>         submitted to client on "writeable" callback. Everything works as
>         I would
>         expect it.
>
>         Now, I want to provide a method to save the sensor data-stream
>         to a file
>         (on the client-side). Easiest way to do so seems to be without
>         websockets, but using a plain HTTP download.
>
>         I tried to achieve a similar functionality using the
>         LWS_CALLBACK_HTTP
>         callback. But there seems no counterpart to the
>         LWS_CALLBACK_SERVER_WRITEABLE callback for HTTP (or non-websockets)
>         connections. Is that true?
>
>         Does anybody know how to handle that? Or is there another (better?)
>         method to send live-data to a file on client-side?
>
>         Any help would be highly appreciated.
>
>
>     You are right, it's missing right now.
>
>     Originally the HTTP stuff was just added to allow lws to deliver a
>     "seed" html script that would make the websocket connections from
>     the client back to the server, as you can see in the test server.
>       That works fine.
>
>     The http file transfer stuff has been upgraded recently to use
>     "writable" callbacks, and to stuff the send channel until just
>     before it would block, but it's special for the case you have a
>     physical file on the server you want to transfer: there's no general
>     way to take care of writeability callback in http as there is in
>     websocket protocol.
>
>     Actually I think that is pretty desirable to also provide it for
>     http. I'll take a look at adding it shortly / tomorrow.
>
>     -Andy
>
>
>     _________________________________________________
>     Libwebsockets mailing list
>     Libwebsockets at ml.__libwebsockets.org
>     <mailto:Libwebsockets at ml.libwebsockets.org>
>     http://ml.libwebsockets.org/__mailman/listinfo/libwebsockets
>     <http://ml.libwebsockets.org/mailman/listinfo/libwebsockets>
>
>




More information about the Libwebsockets mailing list