1d4afb5ceSopenharmony_ci# lws minimal ws server raw vhost
2d4afb5ceSopenharmony_ci
3d4afb5ceSopenharmony_ciThis demonstrates setting up a vhost to listen and accept raw sockets.
4d4afb5ceSopenharmony_ciRaw sockets are just sockets... lws does not send anything on them or
5d4afb5ceSopenharmony_ciinterpret by itself what it receives on them.  So you can implement
6d4afb5ceSopenharmony_ciarbitrary tcp protocols using them.
7d4afb5ceSopenharmony_ci
8d4afb5ceSopenharmony_ciThis isn't very useful standalone as shown here for clarity, but you can
9d4afb5ceSopenharmony_cifreely combine a raw socket vhost with other lws server
10d4afb5ceSopenharmony_ciand client features and other vhosts handling http or ws.
11d4afb5ceSopenharmony_ci
12d4afb5ceSopenharmony_ciBecuase raw socket events have their own callback reasons, the handlers can
13d4afb5ceSopenharmony_cibe integrated in a single protocol that also handles http and ws
14d4afb5ceSopenharmony_ciserver and client callbacks without conflict.
15d4afb5ceSopenharmony_ci
16d4afb5ceSopenharmony_ci## build
17d4afb5ceSopenharmony_ci
18d4afb5ceSopenharmony_ci```
19d4afb5ceSopenharmony_ci $ cmake . && make
20d4afb5ceSopenharmony_ci```
21d4afb5ceSopenharmony_ci
22d4afb5ceSopenharmony_ci## usage
23d4afb5ceSopenharmony_ci
24d4afb5ceSopenharmony_ci -s means listen using tls
25d4afb5ceSopenharmony_ci
26d4afb5ceSopenharmony_ci```
27d4afb5ceSopenharmony_ci $ ./lws-minimal-raw-vhost
28d4afb5ceSopenharmony_ci[2018/03/22 14:49:47:9516] USER: LWS minimal raw vhost
29d4afb5ceSopenharmony_ci[2018/03/22 14:49:47:9673] NOTICE: Creating Vhost 'default' port 7681, 1 protocols, IPv6 off
30d4afb5ceSopenharmony_ci[2018/03/22 14:49:52:3789] USER: LWS_CALLBACK_RAW_ADOPT
31d4afb5ceSopenharmony_ci[2018/03/22 14:49:57:4271] USER: LWS_CALLBACK_RAW_CLOSE
32d4afb5ceSopenharmony_ci```
33d4afb5ceSopenharmony_ci
34d4afb5ceSopenharmony_ci```
35d4afb5ceSopenharmony_ci $ nc localhost 7681
36d4afb5ceSopenharmony_cihello
37d4afb5ceSopenharmony_cihello
38d4afb5ceSopenharmony_ci```
39d4afb5ceSopenharmony_ci
40d4afb5ceSopenharmony_ciConnect one or more sessions to the server using netcat... lines you type
41d4afb5ceSopenharmony_ciinto netcat are sent to the server, which echos them to all connected clients.
42d4afb5ceSopenharmony_ci
43