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/binance
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
..
binance-ss.c examples: move existing to m-e-lowlevel and start repoulating m-e with SS 2021-10-08 09:49:05 +01:00
CMakeLists.txt cmake: bring tls include requirement out as PUBLIC 2021-10-28 08:12:48 +01:00
example-policy.json examples: move existing to m-e-lowlevel and start repoulating m-e with SS 2021-10-08 09:49:05 +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

lws minimal secure streams binance

This is a Secure Streams version of minimal-ws-client-binance.

"policy.json" contains all the information about endpoints, protocols and connection validation, tagged by streamtype name.

The example tries to load it from the cwd, it lives in ./minimal-examples/secure-streams/minimal-secure-streams-binance dir, so either run it from there, or copy the policy.json to your cwd. It's also possible to put the policy json in the code as a string and pass that at context creation time.

The secure stream object represents a nailed-up connection that outlives any single socket connection, and can manage reconnections / retries according to the policy to keep the connection nailed up automatically.

Secure Streams provides the same simplified communication api without any protocol dependencies.

build

Lws must have been built with LWS_ROLE_WS=1, LWS_WITH_SECURE_STREAMS=1, and LWS_WITHOUT_EXTENSIONS=0

 $ cmake . && make

Commandline Options

Option Meaning
-d Set logging verbosity

usage

$ ./bin/lws-minimal-ws-client-binance 
[2021/08/15 06:42:40:8409] U: LWS minimal Secure Streams binance client
[2021/08/15 06:42:40:8410] N: LWS: 4.2.99-v4.2.0-156-g8f352f65e8, NET CLI SRV H1 H2 WS SS-JSON-POL SSPROX ConMon FLTINJ IPV6-on
[2021/08/15 06:42:40:8410] N:  ++ [495958|wsi|0|pipe] (1)
[2021/08/15 06:42:40:8411] N:  ++ [495958|vh|0|netlink] (1)
[2021/08/15 06:42:40:8433] N:  ++ [495958|vh|1|digicert||-1] (2)
[2021/08/15 06:42:40:8471] N:  ++ [495958|wsiSScli|0|binance] (1)
[2021/08/15 06:42:40:8471] N: [495958|wsiSScli|0|binance]: lws_ss_check_next_state_ss: (unset) -> LWSSSCS_CREATING
[2021/08/15 06:42:40:8472] N: [495958|wsiSScli|0|binance]: lws_ss_check_next_state_ss: LWSSSCS_CREATING -> LWSSSCS_CONNECTING
[2021/08/15 06:42:40:8472] N:  ++ [495958|wsicli|0|WS/h1/fstream.binance.com/([495958|wsiSScli|0|binance])] (1)
[2021/08/15 06:42:41:8802] N: [495958|wsiSScli|0|binance]: lws_ss_check_next_state_ss: LWSSSCS_CONNECTING -> LWSSSCS_CONNECTED
[2021/08/15 06:42:42:8803] N: sul_hz_cb: price: min: 4669185¢, max: 4672159¢, avg: 4670061¢, (53 prices/s)
[2021/08/15 06:42:42:8803] N: sul_hz_cb: elatency: min: 131ms, max: 292ms, avg: 154ms, (53 msg/s)
[2021/08/15 06:42:43:8803] N: sul_hz_cb: price: min: 4669646¢, max: 4672159¢, avg: 4669953¢, (34 prices/s)
[2021/08/15 06:42:43:8803] N: sul_hz_cb: elatency: min: 130ms, max: 149ms, avg: 133ms, (34 msg/s)
[2021/08/15 06:42:44:8804] N: sul_hz_cb: price: min: 4669455¢, max: 4672159¢, avg: 4669904¢, (26 prices/s)
...