[Libwebsockets] Newbie Questions

Chad Cravens chad.cravens at ossys.com
Tue Nov 21 04:49:16 CET 2017


Hello!

First, thanks to warmcat for his hard work and a great open source library
for us all to use! I'm a newbie to libwebsockets. I've been working with
the test-apps for a few days now, and I feel like I have a decent grasp of
what's going on but I still have so many questions I'm going to take it one
at a time until I can get a good grasp on the library :)

My first question is regarding HTTP. I have copied the test-server-v2.0.c
source code into my project, and stripped it down to what I believe is the
bare minimum. I have a mount:



*static const struct lws_http_mount mount = {    NULL,    /* linked-list
pointer to next*/    "/",        /* mountpoint in URL namespace on this
vhost */*

and vhost options struct






*static const struct lws_protocol_vhost_options pvo = {    NULL,    NULL,
// &pvo_opt,    "dumb-increment-protocol",    ""};*

I also have a plugin_dirs array:




*static const char * const plugin_dirs[] = {
"/Users/user/myproject/plugins",        NULL};*

I then have a main() function where I
1) set option parameters in a *struct lws_context_creation_info info*
2) create the context with *lws_create_context(&info)*
3) create a vhost with *lws_create_vhost(context, &info)*
4) configure the event loop *lws_uv_sigint_cfg(context, 1, signal_cb)*
5) run the event loop *lws_libuv_run*

When I run the server, I can successfully load the web page in a browser
and connect a websocket client (hooray! \o/). But now....?

What I would like to do first is handle any HTTP requests other than / with
the server itself (not a directory mount). Essentially I want to build a
RESTful service handler for /api/v1/etc, but they all result in 404. I've
tried implementing several of the plugins. It does seem that the plugin is
discovered by libwebsockets, as I see this debug log message:





*[2017/11/20 22:25:17:8362] NOTICE: Plugins:[2017/11/20 22:25:17:8362]
NOTICE: Scanning /Users/user/myproject/plugins[2017/11/20 22:25:17:8364]
NOTICE: protocol_dumb_increment.cpp[2017/11/20 22:25:17:8370] NOTICE:
Creating Vhost 'default' port 8080, 1 protocols, IPv6 off[2017/11/20
22:25:17:8370] NOTICE: mounting file:///Users/user/myproject/web/dist to /*

I have put printf() messages in this plugin file, but nothing is getting
invoked. I have looked for samples on how to statically include this
plugin, but maybe I'm not doing it right?

Maybe I just need some guidance, sample app or a link to some documentation
to get me moving in the right direction on how I can handle HTTP requests
properly and include a static plugin.

Thanks again!

-- 
Chad Cravens
+1 (800) 214-9146 x700
chad.cravens at ossys.com
http://www.ossys.com

[image: Open Source Systems] <https://www.ossys.com>

[image: LinkedIn] <https://www.linkedin.com/company/open-source-systems-llc>
[image: Facebook] <https://www.facebook.com/OpenSrcSys>    [image: Twitter]
<https://www.twitter.com/OpenSrcSys>  [image: YouTube]
<https://www.youtube.com/OpenSrcSys>  [image: Instagram]
<https://www.instagram.com/OpenSrcSys>  [image: RSS Feed]
<http://www.ossys.com/feed>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://libwebsockets.org/pipermail/libwebsockets/attachments/20171120/1276579e/attachment.html>


More information about the Libwebsockets mailing list