blob: aeb5d217913906f0470f0c9705b56ebcd2db49c0 [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
51
Andy Green4739e5c2011-01-22 12:51:57 +000052Testing server with a browser
53-----------------------------
Andy Greened11a022011-01-20 10:23:50 +000054
Andy Greenb2149772010-10-31 13:15:56 +000055If you point your browser (eg, Chrome) to
56
57 http://127.0.0.1:7681
58
Andy Green3c974692010-11-08 17:04:09 +000059It will fetch a script in the form of test.html, and then run the
Andy Green7310e9c2010-11-01 09:12:17 +000060script in there on the browser to open a websocket connection.
61Incrementing numbers should appear in the browser display.
Andy Greenb2149772010-10-31 13:15:56 +000062
Andy Green90c7cbc2011-01-27 06:26:52 +000063Using SSL on the server side
64----------------------------
Andy Green4739e5c2011-01-22 12:51:57 +000065
Andy Green3c974692010-11-08 17:04:09 +000066To test it using SSL/WSS, just run the test server with
67
68$ libwebsockets-test-server --ssl
69
70and use the URL
71
72 https://127.0.0.1:7681
73
74The connection will be entirely encrypted using some generated
75certificates that your browser will not accept, since they are
76not signed by any real Certificate Authority. Just accept the
77certificates in the browser and the connection will proceed
78in first https and then websocket wss, acting exactly the
79same.
80
Andy Greenb2149772010-10-31 13:15:56 +000081test-server.c is all that is needed to use libwebsockets for
82serving both the script html over http and websockets.
83
Andy Green90c7cbc2011-01-27 06:26:52 +000084
Andy Greened11a022011-01-20 10:23:50 +000085Forkless operation
86------------------
87
88If your target device does not offer fork(), you can use
89libwebsockets from your own main loop instead. Use the
90configure option --nofork and simply call libwebsocket_service()
91from your own main loop as shown in the test app sources.
92
Andy Green90c7cbc2011-01-27 06:26:52 +000093
Andy Green4739e5c2011-01-22 12:51:57 +000094Testing websocket client support
95--------------------------------
96
97If you run the test server as described above, you can also
98connect to it using the test client as well as a browser.
99
100$ libwebsockets-test-client localhost
101
102will by default connect to the test server on localhost:7681
103and print the dumb increment number from the server at the
104same time as drawing random circles in the mirror protocol;
105if you connect to the test server using a browser at the
106same time you will be able to see the circles being drawn.
107
Andy Greened11a022011-01-20 10:23:50 +0000108
Andy Green90c7cbc2011-01-27 06:26:52 +0000109Testing SSL on the client side
110------------------------------
111
112To test SSL/WSS client action, just run the client test with
113
114$ libwebsockets-test-client localhost --ssl
115
116By default the client test applet is set to accept selfsigned
117certificates used by the test server, this is indicated by the
118use_ssl var being set to 2. Set it to 1 to reject any server
119certificate that it doesn't have a trusted CA cert for.
120
121
Andy Greena6cbece2011-01-27 20:06:03 +0000122Using the websocket ping utility
123--------------------------------
124
125libwebsockets-test-ping connects as a client to a remote
126websocket server using 04 protocol and pings it like the
127normal unix ping utility.
128
129$ libwebsockets-test-ping localhost
130handshake OK for protocol lws-mirror-protocol
131Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
13264 bytes from localhost: req=1 time=0.1ms
13364 bytes from localhost: req=2 time=0.1ms
13464 bytes from localhost: req=3 time=0.1ms
13564 bytes from localhost: req=4 time=0.2ms
13664 bytes from localhost: req=5 time=0.1ms
13764 bytes from localhost: req=6 time=0.2ms
13864 bytes from localhost: req=7 time=0.2ms
13964 bytes from localhost: req=8 time=0.1ms
140^C
141--- localhost.localdomain websocket ping statistics ---
1428 packets transmitted, 8 received, 0% packet loss, time 7458ms
143rtt min/avg/max = 0.110/0.185/0.218 ms
144$
145
146By default it sends 64 byte payload packets using the 04
147PING packet opcode type. You can change the payload size
148using the -s= flag, up to a maximum of 125 mandated by the
14904 standard.
150
151Using the lws-mirror protocol that is provided by the test
152server, libwebsockets-test-ping can also use larger payload
153sizes up to 4096 is BINARY packets; lws-mirror will copy
154them back to the client and they appear as a PONG. Use the
155-m flag to select this operation.
156
157The default interval between pings is 1s, you can use the -i=
158flag to set this, including fractions like -i=0.01 for 10ms
159interval.
160
161Before you can even use the PING opcode that is part of the
162standard, you must complete a handshake with a specified
163protocol. By default lws-mirror-protocol is used which is
164supported by the test server. But if you are using it on
165another server, you can specify the protcol to handshake with
166by --protocol=protocolname
167
168
Andy Green98a623f2011-03-08 08:43:59 +0000169Fraggle test app
170----------------
171
172By default it runs in server mode
173
174$ libwebsockets-test-fraggle
175libwebsockets test fraggle
176(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
177 Compiled with SSL support, not using it
178 Listening on port 7681
179server sees client connect
180accepted v06 connection
181Spamming 360 random fragments
182Spamming session over, len = 371913. sum = 0x2D3C0AE
183Spamming 895 random fragments
184Spamming session over, len = 875970. sum = 0x6A74DA1
185...
186
187You need to run a second session in client mode, you have to
188give the -c switch and the server address at least:
189
190$ libwebsockets-test-fraggle -c localhost
191libwebsockets test fraggle
192(C) Copyright 2010-2011 Andy Green <andy@warmcat.com> licensed under LGPL2.1
193 Client mode
194Connecting to localhost:7681
195denied deflate-stream extension
196handshake OK for protocol fraggle-protocol
197client connects to server
198EOM received 371913 correctly from 360 fragments
199EOM received 875970 correctly from 895 fragments
200EOM received 247140 correctly from 258 fragments
201EOM received 695451 correctly from 692 fragments
202...
203
204The fraggle test sends a random number up to 1024 fragmented websocket frames
205each of a random size between 1 and 2001 bytes in a single message, then sends
206a checksum and starts sending a new randomly sized and fragmented message.
207
208The fraggle test client receives the same message fragments and computes the
209same checksum using websocket framing to see when the message has ended. It
210then accepts the server checksum message and compares that to its checksum.
211
212
Andy Green9659f372011-01-27 22:01:43 +0000213proxy support
214-------------
215
216The http_proxy environment variable is respected by the client
217connection code for both ws:// and wss://. It doesn't support
218authentication yet.
219
220You use it like this
221
222export http_proxy=myproxy.com:3128
223libwebsockets-test-client someserver.com
224
225
Andy Greened11a022011-01-20 10:23:50 +0000226Websocket version supported
227---------------------------
228
Andy Greene7981dc2011-02-12 21:24:03 +0000229The websocket client code is 04 and 05 version, the server
230supports 00/76 in text mode and 04 and 05 dynamically
231per-connection depending on the version of the
232client / browser.
Andy Greened11a022011-01-20 10:23:50 +0000233
Andy Greene7981dc2011-02-12 21:24:03 +0000234
235External Polling Loop support
236-----------------------------
237
238libwebsockets maintains an internal poll() array for all of its
239sockets, but you can instead integrate the sockets into an
240external polling array. That's needed if libwebsockets will
241cooperate with an existing poll array maintained by another
242server.
243
244Four callbacks LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_DEL_POLL_FD,
245LWS_CALLBACK_SET_MODE_POLL_FD and LWS_CALLBACK_CLEAR_MODE_POLL_FD
246appear in the callback for protocol 0 and allow interface code to
247manage socket descriptors in other poll loops.
248
2492011-02-12 Andy Green <andy@warmcat.com>
Andy Greenb2149772010-10-31 13:15:56 +0000250