Imported Upstream version 3.2
[platform/upstream/libwebsockets.git] / minimal-examples / raw / minimal-raw-file / README.md
1 # lws minimal ws server
2
3 This demonstrates adopting a file descriptor into the lws event
4 loop.  The filepath to open and adopt is given as an argument to the example app, eg
5
6 ```
7  $ ./lws-minimal-raw-file <file>
8 ```
9
10 On a Linux system, some example files for testing might be
11
12  - /proc/self/fd/0      (stdin)
13  - /dev/ttyUSB0         (a USB <-> serial converter)
14  - /dev/input/event<n>  (needs root... input device events)
15
16 The example application opens the file in the protocol init
17 handler, and hexdumps data from the file to the lws log
18 as it becomes available.
19
20 This isn't very useful standalone as shown here for clarity, but you can
21 freely combine raw file descriptor adoption with other lws server
22 and client features.
23
24 Becuase raw file events have their own callback reasons, the handlers can
25 be integrated in a single protocol that also handles http and ws
26 server and client callbacks without conflict.
27
28 ## build
29
30 ```
31  $ cmake . && make
32 ```
33
34 ## usage
35
36 ```
37  $ ./lws-minimal-raw-file /proc/self/fd/0
38 [2018/03/22 10:48:53:9709] USER: LWS minimal raw file
39 [2018/03/22 10:48:53:9876] NOTICE: Creating Vhost 'default' port -2, 1 protocols, IPv6 off
40 [2018/03/22 10:48:55:0037] NOTICE: LWS_CALLBACK_RAW_ADOPT_FILE
41
42 [2018/03/22 10:48:55:9370] NOTICE: LWS_CALLBACK_RAW_RX_FILE
43 [2018/03/22 10:48:55:9377] NOTICE: 
44 [2018/03/22 10:48:55:9408] NOTICE: 0000: 0A                                                 .               
45
46 ```
47
48 The example logs above show the result of typing the Enter key.