clean fraggle
[profile/ivi/libwebsockets.git] / README-test-server
1 Using test-server as a quickstart
2 ---------------------------------
3
4 For a Fedora x86_86 box, the following config line was
5 needed:
6
7  ./configure --prefix=/usr --libdir=/usr/lib64 --enable-openssl
8
9 For Apple systems, Christopher Baker reported that this is needed
10 (and I was told separately enabling openssl makes trouble somehow)
11
12 ./configure CC="gcc -arch i386 -arch x86_64" CXX="g++ -arch i386 -arch
13 x86_64" CPP="gcc -E" CXXCPP="g++ -E" --enable-nofork
14
15
16 otherwise if /usr/local/... and /usr/local/lib are OK then...
17
18 $ ./configure
19 $ make clean
20 $ make
21 $ sudo make install
22 $ libwebsockets-test-server
23
24 should be enough to get a test server listening on port 7861.
25
26 There are a couple of other possible configure options
27
28 --enable-nofork         disables the fork into the background API
29                         and removes all references to fork() and
30                         pr_ctl() from the sources.  Use it if your
31                         platform doesn't support forking.
32
33 --enable-libcrypto      by default libwebsockets uses its own
34                         built-in md5 and sha-1 implementation for
35                         simplicity.  However the libcrypto ones
36                         may be faster, and in a distro context it
37                         may be highly desirable to use a common
38                         library implementation for ease of security
39                         upgrades.  Give this configure option
40                         to disable the built-in ones and force use
41                         of the libcrypto (part of openssl) ones.
42
43 --with-client-cert-dir=dir   tells the client ssl support where to
44                              look for trust certificates to validate
45                              the remote certificate against.
46
47 --enable-noping         Don't try to build the ping test app
48                         It needs some unixy environment that
49                         may choke in other build contexts, this
50                         lets you cleanly stop it being built
51
52 Testing server with a browser
53 -----------------------------
54
55 If you point your browser (eg, Chrome) to
56
57   http://127.0.0.1:7681
58
59 It will fetch a script in the form of test.html, and then run the
60 script in there on the browser to open a websocket connection.
61 Incrementing numbers should appear in the browser display.
62
63 Using SSL on the server side
64 ----------------------------
65
66 To test it using SSL/WSS, just run the test server with
67
68 $ libwebsockets-test-server --ssl
69
70 and use the URL
71
72   https://127.0.0.1:7681
73
74 The connection will be entirely encrypted using some generated
75 certificates that your browser will not accept, since they are
76 not signed by any real Certificate Authority.  Just accept the
77 certificates in the browser and the connection will proceed
78 in first https and then websocket wss, acting exactly the
79 same.
80
81 test-server.c is all that is needed to use libwebsockets for
82 serving both the script html over http and websockets.
83
84
85 Forkless operation
86 ------------------
87
88 If your target device does not offer fork(), you can use
89 libwebsockets from your own main loop instead.  Use the
90 configure option --nofork and simply call libwebsocket_service()
91 from your own main loop as shown in the test app sources.
92
93
94 Testing websocket client support
95 --------------------------------
96
97 If you run the test server as described above, you can also
98 connect to it using the test client as well as a browser.
99
100 $ libwebsockets-test-client localhost
101
102 will by default connect to the test server on localhost:7681
103 and print the dumb increment number from the server at the
104 same time as drawing random circles in the mirror protocol;
105 if you connect to the test server using a browser at the
106 same time you will be able to see the circles being drawn.
107
108
109 Testing SSL on the client side
110 ------------------------------
111
112 To test SSL/WSS client action, just run the client test with
113
114 $ libwebsockets-test-client localhost --ssl
115
116 By default the client test applet is set to accept selfsigned
117 certificates used by the test server, this is indicated by the
118 use_ssl var being set to 2.  Set it to 1 to reject any server
119 certificate that it doesn't have a trusted CA cert for.
120
121
122 Using the websocket ping utility
123 --------------------------------
124
125 libwebsockets-test-ping connects as a client to a remote
126 websocket server using 04 protocol and pings it like the
127 normal unix ping utility.
128
129 $ libwebsockets-test-ping localhost                
130 handshake OK for protocol lws-mirror-protocol
131 Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
132 64 bytes from localhost: req=1 time=0.1ms
133 64 bytes from localhost: req=2 time=0.1ms
134 64 bytes from localhost: req=3 time=0.1ms
135 64 bytes from localhost: req=4 time=0.2ms
136 64 bytes from localhost: req=5 time=0.1ms
137 64 bytes from localhost: req=6 time=0.2ms
138 64 bytes from localhost: req=7 time=0.2ms
139 64 bytes from localhost: req=8 time=0.1ms
140 ^C
141 --- localhost.localdomain websocket ping statistics ---
142 8 packets transmitted, 8 received, 0% packet loss, time 7458ms
143 rtt min/avg/max = 0.110/0.185/0.218 ms
144 $
145
146 By default it sends 64 byte payload packets using the 04
147 PING packet opcode type.  You can change the payload size
148 using the -s= flag, up to a maximum of 125 mandated by the
149 04 standard.
150
151 Using the lws-mirror protocol that is provided by the test
152 server, libwebsockets-test-ping can also use larger payload
153 sizes up to 4096 is BINARY packets; lws-mirror will copy
154 them back to the client and they appear as a PONG.  Use the
155 -m flag to select this operation.
156
157 The default interval between pings is 1s, you can use the -i=
158 flag to set this, including fractions like -i=0.01 for 10ms
159 interval.
160
161 Before you can even use the PING opcode that is part of the
162 standard, you must complete a handshake with a specified
163 protocol.  By default lws-mirror-protocol is used which is
164 supported by the test server.  But if you are using it on
165 another server, you can specify the protcol to handshake with
166 by --protocol=protocolname
167
168
169 Fraggle test app
170 ----------------
171
172 By default it runs in server mode
173
174 $ libwebsockets-test-fraggle
175 libwebsockets test fraggle
176 (C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
177  Compiled with SSL support, not using it
178  Listening on port 7681
179 server sees client connect
180 accepted v06 connection
181 Spamming 360 random fragments
182 Spamming session over, len = 371913. sum = 0x2D3C0AE
183 Spamming 895 random fragments
184 Spamming session over, len = 875970. sum = 0x6A74DA1
185 ...
186
187 You need to run a second session in client mode, you have to
188 give the -c switch and the server address at least:
189
190 $ libwebsockets-test-fraggle -c localhost 
191 libwebsockets test fraggle
192 (C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
193  Client mode
194 Connecting to localhost:7681
195 denied deflate-stream extension
196 handshake OK for protocol fraggle-protocol
197 client connects to server
198 EOM received 371913 correctly from 360 fragments
199 EOM received 875970 correctly from 895 fragments
200 EOM received 247140 correctly from 258 fragments
201 EOM received 695451 correctly from 692 fragments
202 ...
203
204 The fraggle test sends a random number up to 1024 fragmented websocket frames
205 each of a random size between 1 and 2001 bytes in a single message, then sends
206 a checksum and starts sending a new randomly sized and fragmented message.
207
208 The fraggle test client receives the same message fragments and computes the
209 same checksum using websocket framing to see when the message has ended.  It
210 then accepts the server checksum message and compares that to its checksum.
211
212
213 proxy support
214 -------------
215
216 The http_proxy environment variable is respected by the client
217 connection code for both ws:// and wss://.  It doesn't support
218 authentication yet.
219
220 You use it like this
221
222 export http_proxy=myproxy.com:3128
223 libwebsockets-test-client someserver.com
224
225
226 Websocket version supported
227 ---------------------------
228
229 The websocket client code is 04 and 05 version, the server
230 supports 00/76 in text mode and 04 and 05 dynamically
231 per-connection depending on the version of the
232 client / browser.
233
234
235 External Polling Loop support
236 -----------------------------
237
238 libwebsockets maintains an internal poll() array for all of its
239 sockets, but you can instead integrate the sockets into an
240 external polling array.  That's needed if libwebsockets will
241 cooperate with an existing poll array maintained by another
242 server.
243
244 Four callbacks LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_DEL_POLL_FD,
245 LWS_CALLBACK_SET_MODE_POLL_FD and LWS_CALLBACK_CLEAR_MODE_POLL_FD
246 appear in the callback for protocol 0 and allow interface code to
247 manage socket descriptors in other poll loops.
248
249 2011-02-12  Andy Green <andy@warmcat.com>
250