[Libwebsockets] Example using plugin

Andy Green andy at warmcat.com
Thu Jun 28 20:00:42 CEST 2018

On June 29, 2018 1:33:59 AM GMT+08:00, Steve Calfee <stevecalfee at gmail.com> wrote:
>I have successfully integrated http server and http client into my
>app. However, I duplicate lots of the code in the service routine and
>am only interested in such things as handling server post/get calls
>and receiving client results.
>The plugin stuff looks interesting, but I cannot find an example in
>the minimal examples. Can you give me a pointer?

Actually many of the minimal examples split themselves already into a "main" source file and a separate one for the protocol part that can be built as a plugin.  (Although making them "minimal" somewhat conflicted with the reality of that).

There's an example of a standalone plugin + cmake that you can build by itself here, but you should be able to build the protocol part of minimal examples the same way.


Notice once you're a plugin, you can't just directly share filescope pointers etc between the main code and the plugin.  You ideally shouldn't do that anyway... one protocol in the plugin may be used by multiple vhosts with different config.  You can use per-vhost options (pvo) to pass config to individual vhost instantiations of the protocol like this



In the case you use lwsws as the generic server part, and having that get your protocols via plugins, you can set pvo for a protocol in the lwsws JSON config per-vhost; you would pass only strings in the pvo then not pointers.

>Also, I don't understand the git structure. What is the difference
>between 3.0 branch and master? While I am experimenting I would like
>to keep up to date. Once I freeze I would like to have stable branch?

New development happens in master.  When master is working well, it's copied into a stable branch like v3.0-stable.  Only bugfixes go in there.  Master continues with bugfixes and new development.

Right now v3.0-stable was only split from master about a month ago so it's a reasonable choice unless you need something that only exists in master.  Switching between them isn't hard.


>Thanks Steve
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list