1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-23 00:00:06 +01:00
libwebsockets/minimal-examples/client/ws-echo
Andy Green 67f532a8c6 cmake: bring tls include requirement out as PUBLIC
There's no problem for library build, also with LWS_WITH_MINIMAL_EXAMPLES,
but after install at least on OSX, there are problems finding the installed
lws include dir (concealed on most platforms by the path being in the
default search list for the toolchain), and the references in the lws
includes to the tls includes meaning that explicit paths for that must be
available at consuming cmakes.

This patch enhances the cmake config installed by lws to deal with adding
the lws include paths to CMAKE_REQUIRED_INCLUDES and include_directories,
so it can be found before the target is introduced.

The tls include is passed back up the CMakeLists layers and the lws targets
marked with target_include_directories(PUBLIC) with them, so they are
understood as needed by consumers.

More boilerplate is moved out of the example consuming cmakes.

After this, on machines with previous installs of older lws, you may have to
clean out the cmake install path, that is usually something like

/usr/local/lib/cmake/libwebsockets/*

before make installing lws and putting the latest content in there.
2021-10-28 08:12:48 +01:00
..
CMakeLists.txt cmake: bring tls include requirement out as PUBLIC 2021-10-28 08:12:48 +01:00
example-policy.json ss: mass update LE root to ISRG X1 2021-10-08 09:49:06 +01:00
main.c examples: move existing to m-e-lowlevel and start repoulating m-e with SS 2021-10-08 09:49:05 +01:00
README.md examples: move existing to m-e-lowlevel and start repoulating m-e with SS 2021-10-08 09:49:05 +01:00
ws-echo-ss.c examples: move existing to m-e-lowlevel and start repoulating m-e with SS 2021-10-08 09:49:05 +01:00

SS Example "ws-echo"

This shows a client doing ws echo, using Secure Streams.

SS' approach is to segregate "policy" (where and how to connect and authenticate for particular kinds of connection) from payloads that are transferred on the connection. In this case, all the information about the example's policy is in example-policy.json.

Source Purpose
main.c boilerplate to create the lws_context and event loop
ws-echo-ss.c the secure stream user code
example-policy.json the example policy

Build

You should build and install lws itself first. Then with this directory as the cwd, you can use cmake . && make to build the example. This produces ./lws-minimal-ss-ws-echo.

If lws was configured to support SS Proxying with -DLWS_WITH_SECURE_STREAMS_PROXY_API=1, then a second executable is also produced ./lws-minimal-ss-ws-echo-client. This does not try to do its own networking, but instead wants to connect to an SS Proxy process that will fulfil connections itself using its own policy.

Running

You should be able to run the example directly and see it start to send ws messages every 500ms, and receive them back from the lws mirror server.

To go via the SS Proxy, run ./lws-minimal-ss-ws-echo-client and an SS Proxy, eg, the example one found in ./minimal-examples/ssproxy/ssproxy-socket.

Options

Commandline option Meaning
-d <bitmap> Enable logging levels (default 1031 (USER, ERR, WARN, NOTICE), 1039 = +INFO, 1151 = +INFO, DEBUG), -DCMAKE_BUILD_TYPE=DEBUG needed for logs more verbose that NOTICE
--ssproxy-port <port> If going via an SS Proxy, default is Unix Domain Socket @proxy.ss.lws, you can force a different proxy's TCP port with this
--ssproxy-ads <ads> Set non-default hostname or IP address proxy is on
--ssproxy-iface <iface> Set non-default UDS path if starts with +, else interface to bind TCP connection to for proxy