blob: 666cec2f3f18bed3966c91d10e93d99608f358c0 [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
9For Apple systems, in addition to whatever other typical
10configure magic you need, you will also need --enable-nofork and
11it seems don't enable openssl.
Andy Greena1e3ec02010-11-08 17:16:50 +000012
13otherwise if /usr/local/... and /usr/local/lib are OK then...
14
Andy Green8c404152011-02-16 18:50:01 +000015$ ./configure
Andy Green9293b052011-01-23 17:53:54 +000016$ make clean
Andy Green05a0a7b2010-10-31 17:51:39 +000017$ make
Andy Green7310e9c2010-11-01 09:12:17 +000018$ sudo make install
19$ libwebsockets-test-server
Andy Greenb2149772010-10-31 13:15:56 +000020
21should be enough to get a test server listening on port 7861.
22
Andy Green9293b052011-01-23 17:53:54 +000023There are a couple of other possible configure options
24
25--enable-nofork disables the fork into the background API
26 and removes all references to fork() and
27 pr_ctl() from the sources. Use it if your
28 platform doesn't support forking.
29
30--enable-libcrypto by default libwebsockets uses its own
31 built-in md5 and sha-1 implementation for
32 simplicity. However the libcrypto ones
33 may be faster, and in a distro context it
34 may be highly desirable to use a common
35 library implementation for ease of security
36 upgrades. Give this configure option
37 to disable the built-in ones and force use
38 of the libcrypto (part of openssl) ones.
39
Andy Green90c7cbc2011-01-27 06:26:52 +000040--with-client-cert-dir=dir tells the client ssl support where to
41 look for trust certificates to validate
42 the remote certificate against.
43
Andy Greena6cbece2011-01-27 20:06:03 +000044--enable-noping Don't try to build the ping test app
45 It needs some unixy environment that
46 may choke in other build contexts, this
47 lets you cleanly stop it being built
48
Andy Green4739e5c2011-01-22 12:51:57 +000049Testing server with a browser
50-----------------------------
Andy Greened11a022011-01-20 10:23:50 +000051
Andy Greenb2149772010-10-31 13:15:56 +000052If you point your browser (eg, Chrome) to
53
54 http://127.0.0.1:7681
55
Andy Green3c974692010-11-08 17:04:09 +000056It will fetch a script in the form of test.html, and then run the
Andy Green7310e9c2010-11-01 09:12:17 +000057script in there on the browser to open a websocket connection.
58Incrementing numbers should appear in the browser display.
Andy Greenb2149772010-10-31 13:15:56 +000059
Andy Green90c7cbc2011-01-27 06:26:52 +000060Using SSL on the server side
61----------------------------
Andy Green4739e5c2011-01-22 12:51:57 +000062
Andy Green3c974692010-11-08 17:04:09 +000063To test it using SSL/WSS, just run the test server with
64
65$ libwebsockets-test-server --ssl
66
67and use the URL
68
69 https://127.0.0.1:7681
70
71The connection will be entirely encrypted using some generated
72certificates that your browser will not accept, since they are
73not signed by any real Certificate Authority. Just accept the
74certificates in the browser and the connection will proceed
75in first https and then websocket wss, acting exactly the
76same.
77
Andy Greenb2149772010-10-31 13:15:56 +000078test-server.c is all that is needed to use libwebsockets for
79serving both the script html over http and websockets.
80
Andy Green90c7cbc2011-01-27 06:26:52 +000081
Andy Greened11a022011-01-20 10:23:50 +000082Forkless operation
83------------------
84
85If your target device does not offer fork(), you can use
86libwebsockets from your own main loop instead. Use the
87configure option --nofork and simply call libwebsocket_service()
88from your own main loop as shown in the test app sources.
89
Andy Green90c7cbc2011-01-27 06:26:52 +000090
Andy Green4739e5c2011-01-22 12:51:57 +000091Testing websocket client support
92--------------------------------
93
94If you run the test server as described above, you can also
95connect to it using the test client as well as a browser.
96
97$ libwebsockets-test-client localhost
98
99will by default connect to the test server on localhost:7681
100and print the dumb increment number from the server at the
101same time as drawing random circles in the mirror protocol;
102if you connect to the test server using a browser at the
103same time you will be able to see the circles being drawn.
104
Andy Greened11a022011-01-20 10:23:50 +0000105
Andy Green90c7cbc2011-01-27 06:26:52 +0000106Testing SSL on the client side
107------------------------------
108
109To test SSL/WSS client action, just run the client test with
110
111$ libwebsockets-test-client localhost --ssl
112
113By default the client test applet is set to accept selfsigned
114certificates used by the test server, this is indicated by the
115use_ssl var being set to 2. Set it to 1 to reject any server
116certificate that it doesn't have a trusted CA cert for.
117
118
Andy Greena6cbece2011-01-27 20:06:03 +0000119Using the websocket ping utility
120--------------------------------
121
122libwebsockets-test-ping connects as a client to a remote
123websocket server using 04 protocol and pings it like the
124normal unix ping utility.
125
126$ libwebsockets-test-ping localhost
127handshake OK for protocol lws-mirror-protocol
128Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
12964 bytes from localhost: req=1 time=0.1ms
13064 bytes from localhost: req=2 time=0.1ms
13164 bytes from localhost: req=3 time=0.1ms
13264 bytes from localhost: req=4 time=0.2ms
13364 bytes from localhost: req=5 time=0.1ms
13464 bytes from localhost: req=6 time=0.2ms
13564 bytes from localhost: req=7 time=0.2ms
13664 bytes from localhost: req=8 time=0.1ms
137^C
138--- localhost.localdomain websocket ping statistics ---
1398 packets transmitted, 8 received, 0% packet loss, time 7458ms
140rtt min/avg/max = 0.110/0.185/0.218 ms
141$
142
143By default it sends 64 byte payload packets using the 04
144PING packet opcode type. You can change the payload size
145using the -s= flag, up to a maximum of 125 mandated by the
14604 standard.
147
148Using the lws-mirror protocol that is provided by the test
149server, libwebsockets-test-ping can also use larger payload
150sizes up to 4096 is BINARY packets; lws-mirror will copy
151them back to the client and they appear as a PONG. Use the
152-m flag to select this operation.
153
154The default interval between pings is 1s, you can use the -i=
155flag to set this, including fractions like -i=0.01 for 10ms
156interval.
157
158Before you can even use the PING opcode that is part of the
159standard, you must complete a handshake with a specified
160protocol. By default lws-mirror-protocol is used which is
161supported by the test server. But if you are using it on
162another server, you can specify the protcol to handshake with
163by --protocol=protocolname
164
165
Andy Green9659f372011-01-27 22:01:43 +0000166proxy support
167-------------
168
169The http_proxy environment variable is respected by the client
170connection code for both ws:// and wss://. It doesn't support
171authentication yet.
172
173You use it like this
174
175export http_proxy=myproxy.com:3128
176libwebsockets-test-client someserver.com
177
178
Andy Greened11a022011-01-20 10:23:50 +0000179Websocket version supported
180---------------------------
181
Andy Greene7981dc2011-02-12 21:24:03 +0000182The websocket client code is 04 and 05 version, the server
183supports 00/76 in text mode and 04 and 05 dynamically
184per-connection depending on the version of the
185client / browser.
Andy Greened11a022011-01-20 10:23:50 +0000186
Andy Greene7981dc2011-02-12 21:24:03 +0000187
188External Polling Loop support
189-----------------------------
190
191libwebsockets maintains an internal poll() array for all of its
192sockets, but you can instead integrate the sockets into an
193external polling array. That's needed if libwebsockets will
194cooperate with an existing poll array maintained by another
195server.
196
197Four callbacks LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_DEL_POLL_FD,
198LWS_CALLBACK_SET_MODE_POLL_FD and LWS_CALLBACK_CLEAR_MODE_POLL_FD
199appear in the callback for protocol 0 and allow interface code to
200manage socket descriptors in other poll loops.
201
2022011-02-12 Andy Green <andy@warmcat.com>
Andy Greenb2149772010-10-31 13:15:56 +0000203