blob: c140b8b6cde92b4c8112664e03ad48df36e530f6 [file] [log] [blame]
Andy Greenb2149772010-10-31 13:15:56 +00001Using test-server as a quickstart
2---------------------------------
3
Andy Greena1e3ec02010-11-08 17:16:50 +00004For a Fedora x86_86 box, the following config line was
5needed:
6
Andy Green8c404152011-02-16 18:50:01 +00007 ./configure --prefix=/usr --libdir=/usr/lib64 --enable-openssl
8
Andy Greena54986f2011-02-28 07:48:27 +00009For 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
13x86_64" CPP="gcc -E" CXXCPP="g++ -E" --enable-nofork
14
Andy Greena1e3ec02010-11-08 17:16:50 +000015
16otherwise if /usr/local/... and /usr/local/lib are OK then...
17
Andy Green8c404152011-02-16 18:50:01 +000018$ ./configure
Andy Green9293b052011-01-23 17:53:54 +000019$ make clean
Andy Green05a0a7b2010-10-31 17:51:39 +000020$ make
Andy Green7310e9c2010-11-01 09:12:17 +000021$ sudo make install
22$ libwebsockets-test-server
Andy Greenb2149772010-10-31 13:15:56 +000023
24should be enough to get a test server listening on port 7861.
25
Andy Green9293b052011-01-23 17:53:54 +000026There 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
Andy Green90c7cbc2011-01-27 06:26:52 +000043--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
Andy Greena6cbece2011-01-27 20:06:03 +000047--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
Andy Greena41314f2011-05-23 10:00:03 +010051
52--enable-x-google-mux Enable experimental x-google-mux support
53 in the build (see notes later in document)
Andy Greena6cbece2011-01-27 20:06:03 +000054
Andy Green4739e5c2011-01-22 12:51:57 +000055Testing server with a browser
56-----------------------------
Andy Greened11a022011-01-20 10:23:50 +000057
Andy Greenb2149772010-10-31 13:15:56 +000058If you point your browser (eg, Chrome) to
59
60 http://127.0.0.1:7681
61
Andy Green3c974692010-11-08 17:04:09 +000062It will fetch a script in the form of test.html, and then run the
Andy Green7310e9c2010-11-01 09:12:17 +000063script in there on the browser to open a websocket connection.
64Incrementing numbers should appear in the browser display.
Andy Greenb2149772010-10-31 13:15:56 +000065
Andy Green90c7cbc2011-01-27 06:26:52 +000066Using SSL on the server side
67----------------------------
Andy Green4739e5c2011-01-22 12:51:57 +000068
Andy Green3c974692010-11-08 17:04:09 +000069To test it using SSL/WSS, just run the test server with
70
71$ libwebsockets-test-server --ssl
72
73and use the URL
74
75 https://127.0.0.1:7681
76
77The connection will be entirely encrypted using some generated
78certificates that your browser will not accept, since they are
79not signed by any real Certificate Authority. Just accept the
80certificates in the browser and the connection will proceed
81in first https and then websocket wss, acting exactly the
82same.
83
Andy Greenb2149772010-10-31 13:15:56 +000084test-server.c is all that is needed to use libwebsockets for
85serving both the script html over http and websockets.
86
Andy Green90c7cbc2011-01-27 06:26:52 +000087
Andy Greened11a022011-01-20 10:23:50 +000088Forkless operation
89------------------
90
91If your target device does not offer fork(), you can use
92libwebsockets from your own main loop instead. Use the
93configure option --nofork and simply call libwebsocket_service()
94from your own main loop as shown in the test app sources.
95
Andy Green90c7cbc2011-01-27 06:26:52 +000096
Andy Green4739e5c2011-01-22 12:51:57 +000097Testing websocket client support
98--------------------------------
99
100If you run the test server as described above, you can also
101connect to it using the test client as well as a browser.
102
103$ libwebsockets-test-client localhost
104
105will by default connect to the test server on localhost:7681
106and print the dumb increment number from the server at the
107same time as drawing random circles in the mirror protocol;
108if you connect to the test server using a browser at the
109same time you will be able to see the circles being drawn.
110
Andy Greened11a022011-01-20 10:23:50 +0000111
Andy Green90c7cbc2011-01-27 06:26:52 +0000112Testing SSL on the client side
113------------------------------
114
115To test SSL/WSS client action, just run the client test with
116
117$ libwebsockets-test-client localhost --ssl
118
119By default the client test applet is set to accept selfsigned
120certificates used by the test server, this is indicated by the
121use_ssl var being set to 2. Set it to 1 to reject any server
122certificate that it doesn't have a trusted CA cert for.
123
124
Andy Greena6cbece2011-01-27 20:06:03 +0000125Using the websocket ping utility
126--------------------------------
127
128libwebsockets-test-ping connects as a client to a remote
129websocket server using 04 protocol and pings it like the
130normal unix ping utility.
131
132$ libwebsockets-test-ping localhost
133handshake OK for protocol lws-mirror-protocol
134Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
13564 bytes from localhost: req=1 time=0.1ms
13664 bytes from localhost: req=2 time=0.1ms
13764 bytes from localhost: req=3 time=0.1ms
13864 bytes from localhost: req=4 time=0.2ms
13964 bytes from localhost: req=5 time=0.1ms
14064 bytes from localhost: req=6 time=0.2ms
14164 bytes from localhost: req=7 time=0.2ms
14264 bytes from localhost: req=8 time=0.1ms
143^C
144--- localhost.localdomain websocket ping statistics ---
1458 packets transmitted, 8 received, 0% packet loss, time 7458ms
146rtt min/avg/max = 0.110/0.185/0.218 ms
147$
148
149By default it sends 64 byte payload packets using the 04
150PING packet opcode type. You can change the payload size
151using the -s= flag, up to a maximum of 125 mandated by the
15204 standard.
153
154Using the lws-mirror protocol that is provided by the test
155server, libwebsockets-test-ping can also use larger payload
156sizes up to 4096 is BINARY packets; lws-mirror will copy
157them back to the client and they appear as a PONG. Use the
158-m flag to select this operation.
159
160The default interval between pings is 1s, you can use the -i=
161flag to set this, including fractions like -i=0.01 for 10ms
162interval.
163
164Before you can even use the PING opcode that is part of the
165standard, you must complete a handshake with a specified
166protocol. By default lws-mirror-protocol is used which is
167supported by the test server. But if you are using it on
168another server, you can specify the protcol to handshake with
169by --protocol=protocolname
170
171
Andy Green98a623f2011-03-08 08:43:59 +0000172Fraggle test app
173----------------
174
175By default it runs in server mode
176
177$ libwebsockets-test-fraggle
178libwebsockets test fraggle
179(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
180 Compiled with SSL support, not using it
181 Listening on port 7681
182server sees client connect
183accepted v06 connection
184Spamming 360 random fragments
185Spamming session over, len = 371913. sum = 0x2D3C0AE
186Spamming 895 random fragments
187Spamming session over, len = 875970. sum = 0x6A74DA1
188...
189
190You need to run a second session in client mode, you have to
191give the -c switch and the server address at least:
192
193$ libwebsockets-test-fraggle -c localhost
194libwebsockets test fraggle
195(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
196 Client mode
197Connecting to localhost:7681
198denied deflate-stream extension
199handshake OK for protocol fraggle-protocol
200client connects to server
201EOM received 371913 correctly from 360 fragments
202EOM received 875970 correctly from 895 fragments
203EOM received 247140 correctly from 258 fragments
204EOM received 695451 correctly from 692 fragments
205...
206
207The fraggle test sends a random number up to 1024 fragmented websocket frames
208each of a random size between 1 and 2001 bytes in a single message, then sends
209a checksum and starts sending a new randomly sized and fragmented message.
210
211The fraggle test client receives the same message fragments and computes the
212same checksum using websocket framing to see when the message has ended. It
213then accepts the server checksum message and compares that to its checksum.
214
215
Andy Green9659f372011-01-27 22:01:43 +0000216proxy support
217-------------
218
219The http_proxy environment variable is respected by the client
220connection code for both ws:// and wss://. It doesn't support
221authentication yet.
222
223You use it like this
224
225export http_proxy=myproxy.com:3128
226libwebsockets-test-client someserver.com
227
228
Andy Greened11a022011-01-20 10:23:50 +0000229Websocket version supported
230---------------------------
231
Andy Greene7981dc2011-02-12 21:24:03 +0000232The websocket client code is 04 and 05 version, the server
233supports 00/76 in text mode and 04 and 05 dynamically
234per-connection depending on the version of the
235client / browser.
Andy Greened11a022011-01-20 10:23:50 +0000236
Andy Greene7981dc2011-02-12 21:24:03 +0000237
238External Polling Loop support
239-----------------------------
240
241libwebsockets maintains an internal poll() array for all of its
242sockets, but you can instead integrate the sockets into an
243external polling array. That's needed if libwebsockets will
244cooperate with an existing poll array maintained by another
245server.
246
247Four callbacks LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_DEL_POLL_FD,
248LWS_CALLBACK_SET_MODE_POLL_FD and LWS_CALLBACK_CLEAR_MODE_POLL_FD
249appear in the callback for protocol 0 and allow interface code to
250manage socket descriptors in other poll loops.
251
Andy Greena41314f2011-05-23 10:00:03 +0100252
253x-google-mux support
254--------------------
255
256Experimental and super-preliminary x-google-mux support is available if
257enabled in ./configure with --enable-x-google-mux. Note that when changing
258configurations, you will need to do a make distclean before, then the new
259configure and then make ; make install. Don't forget the necessary other
260flags for your platform as described at the top of the readme.
261
262It has the following notes:
263
264 1) To enable it, reconfigure with --enable-x-google-mux
265
Andy Green09226502011-05-28 10:19:19 +0100266 2) It deviates from the google standard by sending full
Andy Greena41314f2011-05-23 10:00:03 +0100267 headers in the addchannel subcommand rather than just
268 changed ones from original connect
269
Andy Green09226502011-05-28 10:19:19 +0100270 3) Quota is not implemented yet
Andy Greena41314f2011-05-23 10:00:03 +0100271
Andy Green09226502011-05-28 10:19:19 +0100272However despite those caveats, in fact it can run the
273test client reliably over one socket (both dumb-increment
274and lws-mirror-protocol), you can open a browser on the
275same test server too and see the circles, etc.
Andy Greena41314f2011-05-23 10:00:03 +0100276
Andy Green09226502011-05-28 10:19:19 +0100277It also works compatibly with deflate-stream automatically.
Andy Greena41314f2011-05-23 10:00:03 +0100278
Andy Green09226502011-05-28 10:19:19 +01002792011-05-28 Andy Green <andy@warmcat.com>
Andy Greenb2149772010-10-31 13:15:56 +0000280