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