blob: e2e0116015fb0d6b4eac8abbfd9f311b5ed3b2a4 [file] [log] [blame]
Andy Greenb2149772010-10-31 13:15:56 +00001Using test-server as a quickstart
2---------------------------------
3
Andy Green71e53692012-07-20 13:00:12 +08004You need to regenerate the autotools and libtoolize stuff for your system
5
6$ autoreconf
7$ libtoolize
8
9Then for a Fedora x86_86 box, the following config line was
Andy Greena1e3ec02010-11-08 17:16:50 +000010needed:
11
Andy Green8c404152011-02-16 18:50:01 +000012 ./configure --prefix=/usr --libdir=/usr/lib64 --enable-openssl
13
Andy Greena54986f2011-02-28 07:48:27 +000014For Apple systems, Christopher Baker reported that this is needed
15(and I was told separately enabling openssl makes trouble somehow)
16
17./configure CC="gcc -arch i386 -arch x86_64" CXX="g++ -arch i386 -arch
18x86_64" CPP="gcc -E" CXXCPP="g++ -E" --enable-nofork
19
Andy Green9c5436c2012-04-12 13:32:47 +080020For mingw build, I did the following to get working build, ping test is
21disabled when building this way
22
231) install mingw64_w32 compiler packages from Fedora
242) additionally install mingw64-zlib package
253) ./configure --prefix=/usr --enable-mingw --host=x86_64-w64-mingw32
264) make
Andy Greena1e3ec02010-11-08 17:16:50 +000027
28otherwise if /usr/local/... and /usr/local/lib are OK then...
29
Andy Green8c404152011-02-16 18:50:01 +000030$ ./configure
Andy Green9293b052011-01-23 17:53:54 +000031$ make clean
Andy Green05a0a7b2010-10-31 17:51:39 +000032$ make
Andy Green7310e9c2010-11-01 09:12:17 +000033$ sudo make install
34$ libwebsockets-test-server
Andy Greenb2149772010-10-31 13:15:56 +000035
36should be enough to get a test server listening on port 7861.
37
Andy Green9293b052011-01-23 17:53:54 +000038There are a couple of other possible configure options
39
40--enable-nofork disables the fork into the background API
41 and removes all references to fork() and
42 pr_ctl() from the sources. Use it if your
43 platform doesn't support forking.
44
45--enable-libcrypto by default libwebsockets uses its own
46 built-in md5 and sha-1 implementation for
47 simplicity. However the libcrypto ones
48 may be faster, and in a distro context it
49 may be highly desirable to use a common
50 library implementation for ease of security
51 upgrades. Give this configure option
52 to disable the built-in ones and force use
53 of the libcrypto (part of openssl) ones.
54
Andy Green90c7cbc2011-01-27 06:26:52 +000055--with-client-cert-dir=dir tells the client ssl support where to
56 look for trust certificates to validate
57 the remote certificate against.
58
Andy Greena6cbece2011-01-27 20:06:03 +000059--enable-noping Don't try to build the ping test app
60 It needs some unixy environment that
61 may choke in other build contexts, this
62 lets you cleanly stop it being built
Andy Greena41314f2011-05-23 10:00:03 +010063
64--enable-x-google-mux Enable experimental x-google-mux support
65 in the build (see notes later in document)
Andy Greena6cbece2011-01-27 20:06:03 +000066
Andy Green4739e5c2011-01-22 12:51:57 +000067Testing server with a browser
68-----------------------------
Andy Greened11a022011-01-20 10:23:50 +000069
Andy Greenb2149772010-10-31 13:15:56 +000070If you point your browser (eg, Chrome) to
71
72 http://127.0.0.1:7681
73
Andy Green3c974692010-11-08 17:04:09 +000074It will fetch a script in the form of test.html, and then run the
Andy Green7310e9c2010-11-01 09:12:17 +000075script in there on the browser to open a websocket connection.
76Incrementing numbers should appear in the browser display.
Andy Greenb2149772010-10-31 13:15:56 +000077
Andy Green90c7cbc2011-01-27 06:26:52 +000078Using SSL on the server side
79----------------------------
Andy Green4739e5c2011-01-22 12:51:57 +000080
Andy Green3c974692010-11-08 17:04:09 +000081To test it using SSL/WSS, just run the test server with
82
83$ libwebsockets-test-server --ssl
84
85and use the URL
86
87 https://127.0.0.1:7681
88
89The connection will be entirely encrypted using some generated
90certificates that your browser will not accept, since they are
91not signed by any real Certificate Authority. Just accept the
92certificates in the browser and the connection will proceed
93in first https and then websocket wss, acting exactly the
94same.
95
Andy Greenb2149772010-10-31 13:15:56 +000096test-server.c is all that is needed to use libwebsockets for
97serving both the script html over http and websockets.
98
Andy Green90c7cbc2011-01-27 06:26:52 +000099
Andy Greened11a022011-01-20 10:23:50 +0000100Forkless operation
101------------------
102
103If your target device does not offer fork(), you can use
104libwebsockets from your own main loop instead. Use the
105configure option --nofork and simply call libwebsocket_service()
106from your own main loop as shown in the test app sources.
107
Andy Green90c7cbc2011-01-27 06:26:52 +0000108
Andy Green4739e5c2011-01-22 12:51:57 +0000109Testing websocket client support
110--------------------------------
111
112If you run the test server as described above, you can also
113connect to it using the test client as well as a browser.
114
115$ libwebsockets-test-client localhost
116
117will by default connect to the test server on localhost:7681
118and print the dumb increment number from the server at the
119same time as drawing random circles in the mirror protocol;
120if you connect to the test server using a browser at the
121same time you will be able to see the circles being drawn.
122
Andy Greened11a022011-01-20 10:23:50 +0000123
Andy Green90c7cbc2011-01-27 06:26:52 +0000124Testing SSL on the client side
125------------------------------
126
127To test SSL/WSS client action, just run the client test with
128
129$ libwebsockets-test-client localhost --ssl
130
131By default the client test applet is set to accept selfsigned
132certificates used by the test server, this is indicated by the
133use_ssl var being set to 2. Set it to 1 to reject any server
134certificate that it doesn't have a trusted CA cert for.
135
136
Andy Greena6cbece2011-01-27 20:06:03 +0000137Using the websocket ping utility
138--------------------------------
139
140libwebsockets-test-ping connects as a client to a remote
141websocket server using 04 protocol and pings it like the
142normal unix ping utility.
143
144$ libwebsockets-test-ping localhost
145handshake OK for protocol lws-mirror-protocol
146Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
14764 bytes from localhost: req=1 time=0.1ms
14864 bytes from localhost: req=2 time=0.1ms
14964 bytes from localhost: req=3 time=0.1ms
15064 bytes from localhost: req=4 time=0.2ms
15164 bytes from localhost: req=5 time=0.1ms
15264 bytes from localhost: req=6 time=0.2ms
15364 bytes from localhost: req=7 time=0.2ms
15464 bytes from localhost: req=8 time=0.1ms
155^C
156--- localhost.localdomain websocket ping statistics ---
1578 packets transmitted, 8 received, 0% packet loss, time 7458ms
158rtt min/avg/max = 0.110/0.185/0.218 ms
159$
160
161By default it sends 64 byte payload packets using the 04
162PING packet opcode type. You can change the payload size
163using the -s= flag, up to a maximum of 125 mandated by the
16404 standard.
165
166Using the lws-mirror protocol that is provided by the test
167server, libwebsockets-test-ping can also use larger payload
168sizes up to 4096 is BINARY packets; lws-mirror will copy
169them back to the client and they appear as a PONG. Use the
170-m flag to select this operation.
171
172The default interval between pings is 1s, you can use the -i=
173flag to set this, including fractions like -i=0.01 for 10ms
174interval.
175
176Before you can even use the PING opcode that is part of the
177standard, you must complete a handshake with a specified
178protocol. By default lws-mirror-protocol is used which is
179supported by the test server. But if you are using it on
180another server, you can specify the protcol to handshake with
181by --protocol=protocolname
182
183
Andy Green98a623f2011-03-08 08:43:59 +0000184Fraggle test app
185----------------
186
187By default it runs in server mode
188
189$ libwebsockets-test-fraggle
190libwebsockets test fraggle
191(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
192 Compiled with SSL support, not using it
193 Listening on port 7681
194server sees client connect
195accepted v06 connection
196Spamming 360 random fragments
197Spamming session over, len = 371913. sum = 0x2D3C0AE
198Spamming 895 random fragments
199Spamming session over, len = 875970. sum = 0x6A74DA1
200...
201
202You need to run a second session in client mode, you have to
203give the -c switch and the server address at least:
204
205$ libwebsockets-test-fraggle -c localhost
206libwebsockets test fraggle
207(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
208 Client mode
209Connecting to localhost:7681
210denied deflate-stream extension
211handshake OK for protocol fraggle-protocol
212client connects to server
213EOM received 371913 correctly from 360 fragments
214EOM received 875970 correctly from 895 fragments
215EOM received 247140 correctly from 258 fragments
216EOM received 695451 correctly from 692 fragments
217...
218
219The fraggle test sends a random number up to 1024 fragmented websocket frames
220each of a random size between 1 and 2001 bytes in a single message, then sends
221a checksum and starts sending a new randomly sized and fragmented message.
222
223The fraggle test client receives the same message fragments and computes the
224same checksum using websocket framing to see when the message has ended. It
225then accepts the server checksum message and compares that to its checksum.
226
227
Andy Green9659f372011-01-27 22:01:43 +0000228proxy support
229-------------
230
231The http_proxy environment variable is respected by the client
232connection code for both ws:// and wss://. It doesn't support
233authentication yet.
234
235You use it like this
236
237export http_proxy=myproxy.com:3128
238libwebsockets-test-client someserver.com
239
240
Andy Greened11a022011-01-20 10:23:50 +0000241Websocket version supported
242---------------------------
243
Andy Greene7981dc2011-02-12 21:24:03 +0000244The websocket client code is 04 and 05 version, the server
245supports 00/76 in text mode and 04 and 05 dynamically
246per-connection depending on the version of the
247client / browser.
Andy Greened11a022011-01-20 10:23:50 +0000248
Andy Greene7981dc2011-02-12 21:24:03 +0000249
250External Polling Loop support
251-----------------------------
252
253libwebsockets maintains an internal poll() array for all of its
254sockets, but you can instead integrate the sockets into an
255external polling array. That's needed if libwebsockets will
256cooperate with an existing poll array maintained by another
257server.
258
259Four callbacks LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_DEL_POLL_FD,
260LWS_CALLBACK_SET_MODE_POLL_FD and LWS_CALLBACK_CLEAR_MODE_POLL_FD
261appear in the callback for protocol 0 and allow interface code to
262manage socket descriptors in other poll loops.
263
Andy Greena41314f2011-05-23 10:00:03 +0100264
265x-google-mux support
266--------------------
267
268Experimental and super-preliminary x-google-mux support is available if
269enabled in ./configure with --enable-x-google-mux. Note that when changing
270configurations, you will need to do a make distclean before, then the new
271configure and then make ; make install. Don't forget the necessary other
272flags for your platform as described at the top of the readme.
273
274It has the following notes:
275
276 1) To enable it, reconfigure with --enable-x-google-mux
277
Andy Green09226502011-05-28 10:19:19 +0100278 2) It deviates from the google standard by sending full
Andy Greena41314f2011-05-23 10:00:03 +0100279 headers in the addchannel subcommand rather than just
280 changed ones from original connect
281
Andy Green09226502011-05-28 10:19:19 +0100282 3) Quota is not implemented yet
Andy Greena41314f2011-05-23 10:00:03 +0100283
Andy Green09226502011-05-28 10:19:19 +0100284However despite those caveats, in fact it can run the
285test client reliably over one socket (both dumb-increment
286and lws-mirror-protocol), you can open a browser on the
287same test server too and see the circles, etc.
Andy Greena41314f2011-05-23 10:00:03 +0100288
Andy Green09226502011-05-28 10:19:19 +0100289It also works compatibly with deflate-stream automatically.
Andy Greena41314f2011-05-23 10:00:03 +0100290
Andy Green9c5436c2012-04-12 13:32:47 +08002912012-04-12 Andy Green <andy@warmcat.com>
Andy Greenb2149772010-10-31 13:15:56 +0000292