[Libwebsockets] Curl and libwebsockets

Andy Green andy at warmcat.com
Fri Sep 26 10:44:45 CEST 2014

On 26 September 2014 16:24:17 GMT+08:00, Thomas Spitz <thomas.spitz at gmail.com> wrote:
>Hello everyone,
>First of all, thanks a lot for Andy's wonderful library and support!
>I am using libwebsocket for websocket communication and Html web
>Now I would like my server to :

lws has to deal with HTTP to some extent, because every websocket connection starts out as an HTTP connection.  So you could think about these easily enough

>  - send some HTTP/HTTPS commands (egg: in order to trigger an external
>   device )
>- receive some HTTP/HTTPS commands (egg: in order to be triggered by an
>   external device)

These ones are out of scope for directly dealing with in a "websocket library" -->

>   - transfer some files using ftp, ftps
>   - send emails using smtp, smtps
>   - manage transfer to a NAS server
>   - eventually stream an audio/video file using RTSP

You will have to write stuff in your "user code" outside of lws to deal with them.

>My idea was to use libcurl for the functions above but maybe
>could already do some of those functions better/easier (I am newby with
>libcurl)? Does libcurl and libwebsockets can be used at the same time
>without any problem?

If you look at the test server, it shows how to server arbitrary http stuff and how to use the headers and ?a=b&c=d type parsing helpers already in lws.  So serving via http should be pretty simple to do inside lws.

Initiating HTTP is only supported by the client code to send the upgrade header.  I think it's not enough.  That's simple enough to write, but dealing with it in a nonblocking way is more complex.  You might want to spawn a thread that does it by libcurl or for a quick hack just fork and exec curl with the right arguments.

But the serving bit should already do what you want.


>Best regards,
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list