blob: b31ed62fdf983612088070d9e556b8a7ef7d3cfb [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 Green9659f372011-01-27 22:01:43 +0000169proxy support
170-------------
171
172The http_proxy environment variable is respected by the client
173connection code for both ws:// and wss://. It doesn't support
174authentication yet.
175
176You use it like this
177
178export http_proxy=myproxy.com:3128
179libwebsockets-test-client someserver.com
180
181
Andy Greened11a022011-01-20 10:23:50 +0000182Websocket version supported
183---------------------------
184
Andy Greene7981dc2011-02-12 21:24:03 +0000185The websocket client code is 04 and 05 version, the server
186supports 00/76 in text mode and 04 and 05 dynamically
187per-connection depending on the version of the
188client / browser.
Andy Greened11a022011-01-20 10:23:50 +0000189
Andy Greene7981dc2011-02-12 21:24:03 +0000190
191External Polling Loop support
192-----------------------------
193
194libwebsockets maintains an internal poll() array for all of its
195sockets, but you can instead integrate the sockets into an
196external polling array. That's needed if libwebsockets will
197cooperate with an existing poll array maintained by another
198server.
199
200Four callbacks LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_DEL_POLL_FD,
201LWS_CALLBACK_SET_MODE_POLL_FD and LWS_CALLBACK_CLEAR_MODE_POLL_FD
202appear in the callback for protocol 0 and allow interface code to
203manage socket descriptors in other poll loops.
204
2052011-02-12 Andy Green <andy@warmcat.com>
Andy Greenb2149772010-10-31 13:15:56 +0000206