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