blob: f8fb0503caace0eb07246e6ae7c703bd33c450cd [file] [log] [blame]
Andy Green6c1f64e2013-01-20 11:28:06 +08001Testing server with a browser
2-----------------------------
3
4If you run libwebsockets-test-server and point your browser
5(eg, Chrome) to
6
7 http://127.0.0.1:7681
8
9It will fetch a script in the form of test.html, and then run the
10script in there on the browser to open a websocket connection.
11Incrementing numbers should appear in the browser display.
12
13By default the test server logs to both stderr and syslog, you can control
14what is logged using -d <log level>, see later.
15
16
17Running test server as a Daemon
18-------------------------------
19
20You can use the -D option on the test server to have it fork into the
21background and return immediately. In this daemonized mode all stderr is
22disabled and logging goes only to syslog, eg, /var/log/messages or similar.
23
24The server maintains a lockfile at /tmp/.lwsts-lock that contains the pid
25of the master process, and deletes this file when the master process
26terminates.
27
28To stop the daemon, do
29
30 kill `cat /tmp/.lwsts-lock`
31
32If it finds a stale lock (the pid mentioned in the file does not exist
33any more) it will delete the lock and create a new one during startup.
34
35If the lock is valid, the daemon will exit with a note on stderr that
36it was already running.s
37
38
39Using SSL on the server side
40----------------------------
41
42To test it using SSL/WSS, just run the test server with
43
44$ libwebsockets-test-server --ssl
45
46and use the URL
47
48 https://127.0.0.1:7681
49
50The connection will be entirely encrypted using some generated
51certificates that your browser will not accept, since they are
52not signed by any real Certificate Authority. Just accept the
53certificates in the browser and the connection will proceed
54in first https and then websocket wss, acting exactly the
55same.
56
57test-server.c is all that is needed to use libwebsockets for
58serving both the script html over http and websockets.
59
60
Andy Green6c1f64e2013-01-20 11:28:06 +080061Testing websocket client support
62--------------------------------
63
64If you run the test server as described above, you can also
65connect to it using the test client as well as a browser.
66
67$ libwebsockets-test-client localhost
68
69will by default connect to the test server on localhost:7681
70and print the dumb increment number from the server at the
71same time as drawing random circles in the mirror protocol;
72if you connect to the test server using a browser at the
73same time you will be able to see the circles being drawn.
74
75
Andy Green769153e2013-01-30 11:03:01 +080076Testing simple echo
77-------------------
78
79You can test against echo.websockets.org as a sanity test like
80this (the client connects to port 80 by default):
81
82$ libwebsockets-test-echo --client echo.websocket.org
83
84This echo test is of limited use though because it doesn't
85negotiate any protocol. You can run the same test app as a
86local server, by default on localhost:7681
87
88$ libwebsockets-test-echo
89
90and do the echo test against the local echo server
91
92$ libwebsockets-test-echo --client localhost --port 7681
93
94If you add the --ssl switch to both the client and server, you can also test
95with an encrypted link.
96
97
Andy Green6c1f64e2013-01-20 11:28:06 +080098Testing SSL on the client side
99------------------------------
100
101To test SSL/WSS client action, just run the client test with
102
103$ libwebsockets-test-client localhost --ssl
104
105By default the client test applet is set to accept selfsigned
106certificates used by the test server, this is indicated by the
107use_ssl var being set to 2. Set it to 1 to reject any server
108certificate that it doesn't have a trusted CA cert for.
109
110
111Using the websocket ping utility
112--------------------------------
113
114libwebsockets-test-ping connects as a client to a remote
115websocket server using 04 protocol and pings it like the
116normal unix ping utility.
117
118$ libwebsockets-test-ping localhost
119handshake OK for protocol lws-mirror-protocol
120Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
12164 bytes from localhost: req=1 time=0.1ms
12264 bytes from localhost: req=2 time=0.1ms
12364 bytes from localhost: req=3 time=0.1ms
12464 bytes from localhost: req=4 time=0.2ms
12564 bytes from localhost: req=5 time=0.1ms
12664 bytes from localhost: req=6 time=0.2ms
12764 bytes from localhost: req=7 time=0.2ms
12864 bytes from localhost: req=8 time=0.1ms
129^C
130--- localhost.localdomain websocket ping statistics ---
1318 packets transmitted, 8 received, 0% packet loss, time 7458ms
132rtt min/avg/max = 0.110/0.185/0.218 ms
133$
134
135By default it sends 64 byte payload packets using the 04
136PING packet opcode type. You can change the payload size
137using the -s= flag, up to a maximum of 125 mandated by the
13804 standard.
139
140Using the lws-mirror protocol that is provided by the test
141server, libwebsockets-test-ping can also use larger payload
142sizes up to 4096 is BINARY packets; lws-mirror will copy
143them back to the client and they appear as a PONG. Use the
144-m flag to select this operation.
145
146The default interval between pings is 1s, you can use the -i=
147flag to set this, including fractions like -i=0.01 for 10ms
148interval.
149
150Before you can even use the PING opcode that is part of the
151standard, you must complete a handshake with a specified
152protocol. By default lws-mirror-protocol is used which is
153supported by the test server. But if you are using it on
154another server, you can specify the protcol to handshake with
155by --protocol=protocolname
156
157
158Fraggle test app
159----------------
160
161By default it runs in server mode
162
163$ libwebsockets-test-fraggle
164libwebsockets test fraggle
165(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
166 Compiled with SSL support, not using it
167 Listening on port 7681
168server sees client connect
169accepted v06 connection
170Spamming 360 random fragments
171Spamming session over, len = 371913. sum = 0x2D3C0AE
172Spamming 895 random fragments
173Spamming session over, len = 875970. sum = 0x6A74DA1
174...
175
176You need to run a second session in client mode, you have to
177give the -c switch and the server address at least:
178
179$ libwebsockets-test-fraggle -c localhost
180libwebsockets test fraggle
181(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
182 Client mode
183Connecting to localhost:7681
184denied deflate-stream extension
185handshake OK for protocol fraggle-protocol
186client connects to server
187EOM received 371913 correctly from 360 fragments
188EOM received 875970 correctly from 895 fragments
189EOM received 247140 correctly from 258 fragments
190EOM received 695451 correctly from 692 fragments
191...
192
193The fraggle test sends a random number up to 1024 fragmented websocket frames
194each of a random size between 1 and 2001 bytes in a single message, then sends
195a checksum and starts sending a new randomly sized and fragmented message.
196
197The fraggle test client receives the same message fragments and computes the
198same checksum using websocket framing to see when the message has ended. It
199then accepts the server checksum message and compares that to its checksum.
200
201
202proxy support
203-------------
204
205The http_proxy environment variable is respected by the client
206connection code for both ws:// and wss://. It doesn't support
207authentication.
208
209You use it like this
210
211export http_proxy=myproxy.com:3128
212libwebsockets-test-client someserver.com
213
214
215debug logging
216-------------
217
218By default logging of severity "notice", "warn" or "err" is enabled to stderr.
219
220Again by default other logging is comiled in but disabled from printing.
221
222If you want to eliminate the debug logging below notice in severity, use the
223--disable-debug configure option to have it removed from the code by the
224preprocesser.
225
226If you want to see more detailed debug logs, you can control a bitfield to
227select which logs types may print using the lws_set_log_level() api, in the
228test apps you can use -d <number> to control this. The types of logging
229available are (OR together the numbers to select multiple)
230
231 1 ERR
232 2 WARN
233 4 NOTICE
234 8 INFO
235 16 DEBUG
236 32 PARSER
237 64 HEADER
238 128 EXTENSION
239 256 CLIENT
Andy Greend636e352013-01-29 12:36:17 +0800240 512 LATENCY
Andy Green6c1f64e2013-01-20 11:28:06 +0800241
242
243Websocket version supported
244---------------------------
245
Andy Green3b228c52013-01-30 08:31:43 +0800246The final IETF standard is supported for both client and server, protocol
247version 13.
Andy Green6c1f64e2013-01-20 11:28:06 +0800248
249
Andy Greend636e352013-01-29 12:36:17 +0800250Latency Tracking
251----------------
252
253Since libwebsockets runs using poll() and a single threaded approach, any
254unexpected latency coming from system calls would be bad news. There's now
255a latency tracking scheme that can be built in with --with-latency at
256configure-time, logging the time taken for system calls to complete and if
257the whole action did complete that time or was deferred.
258
259You can see the detailed data by enabling logging level 512 (eg, -d 519 on
260the test server to see that and the usual logs), however even without that
261the "worst" latency is kept and reported to the logs with NOTICE severity
262when the context is destroyed.
263
264Some care is needed interpreting them, if the action completed the first figure
265(in us) is the time taken for the whole action, which may have retried through
266the poll loop many times and will depend on network roundtrip times. High
267figures here don't indicate a problem. The figure in us reported after "lat"
268in the logging is the time taken by this particular attempt. High figures
269here may indicate a problem, or if you system is loaded with another app at
270that time, such as the browser, it may simply indicate the OS gave preferential
271treatment to the other app during that call.
272