blob: 1cb8e8463f6d3ecd2120ca7d855b752566672477 [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
7./configure --prefix=/usr --libdir=/usr/lib64 --enable-openssl
8
9otherwise if /usr/local/... and /usr/local/lib are OK then...
10
Andy Green3c974692010-11-08 17:04:09 +000011$ ./configure --enable-openssl
Andy Green9293b052011-01-23 17:53:54 +000012$ make clean
Andy Green05a0a7b2010-10-31 17:51:39 +000013$ make
Andy Green7310e9c2010-11-01 09:12:17 +000014$ sudo make install
15$ libwebsockets-test-server
Andy Greenb2149772010-10-31 13:15:56 +000016
17should be enough to get a test server listening on port 7861.
18
Andy Green9293b052011-01-23 17:53:54 +000019There are a couple of other possible configure options
20
21--enable-nofork disables the fork into the background API
22 and removes all references to fork() and
23 pr_ctl() from the sources. Use it if your
24 platform doesn't support forking.
25
26--enable-libcrypto by default libwebsockets uses its own
27 built-in md5 and sha-1 implementation for
28 simplicity. However the libcrypto ones
29 may be faster, and in a distro context it
30 may be highly desirable to use a common
31 library implementation for ease of security
32 upgrades. Give this configure option
33 to disable the built-in ones and force use
34 of the libcrypto (part of openssl) ones.
35
Andy Green90c7cbc2011-01-27 06:26:52 +000036--with-client-cert-dir=dir tells the client ssl support where to
37 look for trust certificates to validate
38 the remote certificate against.
39
Andy Greena6cbece2011-01-27 20:06:03 +000040--enable-noping Don't try to build the ping test app
41 It needs some unixy environment that
42 may choke in other build contexts, this
43 lets you cleanly stop it being built
44
Andy Green4739e5c2011-01-22 12:51:57 +000045Testing server with a browser
46-----------------------------
Andy Greened11a022011-01-20 10:23:50 +000047
Andy Greenb2149772010-10-31 13:15:56 +000048If you point your browser (eg, Chrome) to
49
50 http://127.0.0.1:7681
51
Andy Green3c974692010-11-08 17:04:09 +000052It will fetch a script in the form of test.html, and then run the
Andy Green7310e9c2010-11-01 09:12:17 +000053script in there on the browser to open a websocket connection.
54Incrementing numbers should appear in the browser display.
Andy Greenb2149772010-10-31 13:15:56 +000055
Andy Green90c7cbc2011-01-27 06:26:52 +000056Using SSL on the server side
57----------------------------
Andy Green4739e5c2011-01-22 12:51:57 +000058
Andy Green3c974692010-11-08 17:04:09 +000059To test it using SSL/WSS, just run the test server with
60
61$ libwebsockets-test-server --ssl
62
63and use the URL
64
65 https://127.0.0.1:7681
66
67The connection will be entirely encrypted using some generated
68certificates that your browser will not accept, since they are
69not signed by any real Certificate Authority. Just accept the
70certificates in the browser and the connection will proceed
71in first https and then websocket wss, acting exactly the
72same.
73
Andy Greenb2149772010-10-31 13:15:56 +000074test-server.c is all that is needed to use libwebsockets for
75serving both the script html over http and websockets.
76
Andy Green90c7cbc2011-01-27 06:26:52 +000077
Andy Greened11a022011-01-20 10:23:50 +000078Forkless operation
79------------------
80
81If your target device does not offer fork(), you can use
82libwebsockets from your own main loop instead. Use the
83configure option --nofork and simply call libwebsocket_service()
84from your own main loop as shown in the test app sources.
85
Andy Green90c7cbc2011-01-27 06:26:52 +000086
Andy Green4739e5c2011-01-22 12:51:57 +000087Testing websocket client support
88--------------------------------
89
90If you run the test server as described above, you can also
91connect to it using the test client as well as a browser.
92
93$ libwebsockets-test-client localhost
94
95will by default connect to the test server on localhost:7681
96and print the dumb increment number from the server at the
97same time as drawing random circles in the mirror protocol;
98if you connect to the test server using a browser at the
99same time you will be able to see the circles being drawn.
100
Andy Greened11a022011-01-20 10:23:50 +0000101
Andy Green90c7cbc2011-01-27 06:26:52 +0000102Testing SSL on the client side
103------------------------------
104
105To test SSL/WSS client action, just run the client test with
106
107$ libwebsockets-test-client localhost --ssl
108
109By default the client test applet is set to accept selfsigned
110certificates used by the test server, this is indicated by the
111use_ssl var being set to 2. Set it to 1 to reject any server
112certificate that it doesn't have a trusted CA cert for.
113
114
Andy Greena6cbece2011-01-27 20:06:03 +0000115Using the websocket ping utility
116--------------------------------
117
118libwebsockets-test-ping connects as a client to a remote
119websocket server using 04 protocol and pings it like the
120normal unix ping utility.
121
122$ libwebsockets-test-ping localhost
123handshake OK for protocol lws-mirror-protocol
124Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data.
12564 bytes from localhost: req=1 time=0.1ms
12664 bytes from localhost: req=2 time=0.1ms
12764 bytes from localhost: req=3 time=0.1ms
12864 bytes from localhost: req=4 time=0.2ms
12964 bytes from localhost: req=5 time=0.1ms
13064 bytes from localhost: req=6 time=0.2ms
13164 bytes from localhost: req=7 time=0.2ms
13264 bytes from localhost: req=8 time=0.1ms
133^C
134--- localhost.localdomain websocket ping statistics ---
1358 packets transmitted, 8 received, 0% packet loss, time 7458ms
136rtt min/avg/max = 0.110/0.185/0.218 ms
137$
138
139By default it sends 64 byte payload packets using the 04
140PING packet opcode type. You can change the payload size
141using the -s= flag, up to a maximum of 125 mandated by the
14204 standard.
143
144Using the lws-mirror protocol that is provided by the test
145server, libwebsockets-test-ping can also use larger payload
146sizes up to 4096 is BINARY packets; lws-mirror will copy
147them back to the client and they appear as a PONG. Use the
148-m flag to select this operation.
149
150The default interval between pings is 1s, you can use the -i=
151flag to set this, including fractions like -i=0.01 for 10ms
152interval.
153
154Before you can even use the PING opcode that is part of the
155standard, you must complete a handshake with a specified
156protocol. By default lws-mirror-protocol is used which is
157supported by the test server. But if you are using it on
158another server, you can specify the protcol to handshake with
159by --protocol=protocolname
160
161
Andy Green9659f372011-01-27 22:01:43 +0000162proxy support
163-------------
164
165The http_proxy environment variable is respected by the client
166connection code for both ws:// and wss://. It doesn't support
167authentication yet.
168
169You use it like this
170
171export http_proxy=myproxy.com:3128
172libwebsockets-test-client someserver.com
173
174
Andy Greened11a022011-01-20 10:23:50 +0000175Websocket version supported
176---------------------------
177
Andy Green4739e5c2011-01-22 12:51:57 +0000178The websocket client code is 04 version, the server supports
179both 00/76 in text mode and 04 dynamically per-connection
180depending on the version of the client / browser.
Andy Greened11a022011-01-20 10:23:50 +0000181
Andy Green4739e5c2011-01-22 12:51:57 +00001822011-01-22 Andy Green <andy@warmcat.com>
Andy Greenb2149772010-10-31 13:15:56 +0000183