[Libwebsockets] v2.0 coming very soon

Andy Green andy at warmcat.com
Sun Apr 24 20:20:24 CEST 2016



On April 24, 2016 9:28:32 PM GMT+08:00, Thomas Spitz <thomas.spitz at hestia-france.com> wrote:
>Hello Andy, hello everyone,

(adding back the ml)

>I have looked at the new features you have introduced and I wonder
>whether
>this could solve one of the old issue we discussed in the following
>posts :
>https://libwebsockets.org/pipermail/libwebsockets/2016-January/002164.html
>https://libwebsockets.org/pipermail/libwebsockets/2014-September/001355.html
>
>To make it clearer, here is my application :
>At the present, I use libwebsocket on an embedded linux (1core 450MHz
>ARM)
>mainly to communicate (two-way communication) in real time through one
>port
>(SSL port 443) with desktop softwares, mobile apps and also browsers
>(less
>important) using my own protocol over websocket.
>
>I now also need to retrieve files that are stored on my embedded linux
>(data log files, pictures, sounds, ....) in a simple way (eg: a bit
>like a
>ftp) but using the same port 443? Thus, we only need to create one NAT
>rule
>in routers to access our embedded linux server from the WAN.

Right... you could always do that on one port by choosing what files to serve in the http callback.  For example the test-server serves both his ws connections and the html and png all on one port.  But for that you had to write the low-level code.

Master branch (to be lws v2.0) gives you two additional options

 1) Keep your existing code and attach your own mounts at vhost creation time

https://github.com/warmcat/libwebsockets/blob/master/README.coding.md#using-lws-v2-vhosts

Lws will serve the mounted contents automatically from where it's mounted in the server namespace

 2) Replace your whole server app with lwsws, which is how libwebsockets.org is working now.

https://github.com/warmcat/libwebsockets/blob/master/README.lwsws.md

Then you can configure the vhosts and mounts (and everything else) in JSON instead of writing code.

https://github.com/warmcat/libwebsockets/blob/master/lwsws/etc-lwsws-conf-EXAMPLE
https://github.com/warmcat/libwebsockets/blob/master/lwsws/etc-lwsws-conf.d-localhost-EXAMPLE

To implement your custom ws protocol part, do it as an lws protocol plugin.  These are much simpler and more selfcontained than 'cut and paste the test server'... eg

https://github.com/warmcat/libwebsockets/blob/master/plugins/protocol_dumb_increment.c

You can build your plugin against lws headers and libs, and copy to  /usr/[local/]share/libwebsockets-test-server/plugins/, lws scans the dir and initializes any plugins found.

You need to enable the ws protocols you want to offer in each vhost, see how the libwebsockets.org conf above does it.  You can also set per vhost protocol options there to modify or control what yhe protocol plugin does on a per-vhost basis.

This way you can shed almost all your custom server code and get more featureful and maintainable results.

-Andy

>If I am correct, it seems that vhost can help us to have the standard
>LWS
>webserver, the WS server and a kind of "FTP" all running on the same
>443
>port? If so, do you have an idea of a service that could work with LWS
>in
>order to serve files from an embedded linux file system? Ideally, I
>wouldn't like to have to create my own protocol to retrieve files from
>my
>filesystem.
>
>Thanks in advance for your very nice support and sorry for such novice
>questions.
>
>Best regards,
>Thomas
>
>
>2016-04-23 14:12 GMT+02:00 Andy Green <andy at warmcat.com>:
>
>> Hi -
>>
>> In the spirit of eating my own dogfood the last couple of weeks my
>own web
>> services for https://libwebsockets.org and https://warmcat.com have
>been
>> running using lwsws on master, with real traffic and with real CGIs
>(cgit +
>> mailman).
>>
>> After tracking down the last CGI related bugs this week, it seems to
>be
>> stable.
>>
>> It's running 11 vhosts, although a lot of these are redirects for
>older
>> services.  You can see its current status (via websockets, naturally)
>here:
>>
>> https://libwebsockets.org/server-status/
>>
>> (This is a ws protocol plugin on lwsws and is included in ./plugins)
>>
>> I've prepared a page listing the new features here
>>
>> https://libwebsockets.org/lws-2.0-new-features.html
>>
>> Basically a big advantage is if you are making a server type
>application,
>> you can just use lwsws and only need to write the ws protocol plugin
>and
>> set up some JSON to deploy it, instead of cut and pasting custom
>code.
>>
>> If you want to deploy more protocols later, they are selfcontained
>plugins
>> and will play nice together.  The server stack is already much more
>mature
>> than 1.7 (the automated mountpoint serving and http cache control,
>> apache-compatible logging amongst other things).  And you can benefit
>from
>> centralized maintenance of the whole server stack that way.
>>
>> For example the lws test server on
>https://libwebsockets.org/testserver
>> has its ws protocols served by lwsws plugins; there's no code at all
>about
>> them in lwsws itself.
>>
>> If you don't care right now, well it's disabled in cmake by default
>> currently and everything works as before by default.
>>
>> There's some docs on lwsws here:
>>
>> https://github.com/warmcat/libwebsockets/blob/master/README.lwsws.md
>>
>> and you can see the actual lwsws JSON config for libwebsockets.org in
>the
>> tree as an example
>>
>>
>>
>https://github.com/warmcat/libwebsockets/blob/master/lwsws/etc-lwsws-conf.d-localhost-EXAMPLE
>>
>> There are two features that will have to wait for a subsequent
>version I
>> think, one is http proxy, although it works it's not integrated into
>lwsws
>> yet (because I don't have a use for it right now and nobody has asked
>for
>> it), the other is mbedtls (people asking for it but nobody wants it
>enough
>> to help work on it, even though I have done all the plumbing).
>>
>> Otherwise it's in good shape AFAICT, it was in Coverity today and
>it's
>> back at zero defects.
>>
>> If there's any comments, questions or suggestions, it'd be helpful to
>hear
>> them before it gets released ^^
>>
>> -Andy
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> http://libwebsockets.org/mailman/listinfo/libwebsockets
>>




More information about the Libwebsockets mailing list