Andy Green | b214977 | 2010-10-31 13:15:56 +0000 | [diff] [blame] | 1 | Using test-server as a quickstart |
| 2 | --------------------------------- |
| 3 | |
Andy Green | a1e3ec0 | 2010-11-08 17:16:50 +0000 | [diff] [blame] | 4 | For a Fedora x86_86 box, the following config line was |
| 5 | needed: |
| 6 | |
| 7 | ./configure --prefix=/usr --libdir=/usr/lib64 --enable-openssl |
| 8 | |
| 9 | otherwise if /usr/local/... and /usr/local/lib are OK then... |
| 10 | |
Andy Green | 3c97469 | 2010-11-08 17:04:09 +0000 | [diff] [blame] | 11 | $ ./configure --enable-openssl |
Andy Green | 9293b05 | 2011-01-23 17:53:54 +0000 | [diff] [blame] | 12 | $ make clean |
Andy Green | 05a0a7b | 2010-10-31 17:51:39 +0000 | [diff] [blame] | 13 | $ make |
Andy Green | 7310e9c | 2010-11-01 09:12:17 +0000 | [diff] [blame] | 14 | $ sudo make install |
| 15 | $ libwebsockets-test-server |
Andy Green | b214977 | 2010-10-31 13:15:56 +0000 | [diff] [blame] | 16 | |
| 17 | should be enough to get a test server listening on port 7861. |
| 18 | |
Andy Green | 9293b05 | 2011-01-23 17:53:54 +0000 | [diff] [blame] | 19 | There 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 Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 36 | --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 Green | a6cbece | 2011-01-27 20:06:03 +0000 | [diff] [blame] | 40 | --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 Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 45 | Testing server with a browser |
| 46 | ----------------------------- |
Andy Green | ed11a02 | 2011-01-20 10:23:50 +0000 | [diff] [blame] | 47 | |
Andy Green | b214977 | 2010-10-31 13:15:56 +0000 | [diff] [blame] | 48 | If you point your browser (eg, Chrome) to |
| 49 | |
| 50 | http://127.0.0.1:7681 |
| 51 | |
Andy Green | 3c97469 | 2010-11-08 17:04:09 +0000 | [diff] [blame] | 52 | It will fetch a script in the form of test.html, and then run the |
Andy Green | 7310e9c | 2010-11-01 09:12:17 +0000 | [diff] [blame] | 53 | script in there on the browser to open a websocket connection. |
| 54 | Incrementing numbers should appear in the browser display. |
Andy Green | b214977 | 2010-10-31 13:15:56 +0000 | [diff] [blame] | 55 | |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 56 | Using SSL on the server side |
| 57 | ---------------------------- |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 58 | |
Andy Green | 3c97469 | 2010-11-08 17:04:09 +0000 | [diff] [blame] | 59 | To test it using SSL/WSS, just run the test server with |
| 60 | |
| 61 | $ libwebsockets-test-server --ssl |
| 62 | |
| 63 | and use the URL |
| 64 | |
| 65 | https://127.0.0.1:7681 |
| 66 | |
| 67 | The connection will be entirely encrypted using some generated |
| 68 | certificates that your browser will not accept, since they are |
| 69 | not signed by any real Certificate Authority. Just accept the |
| 70 | certificates in the browser and the connection will proceed |
| 71 | in first https and then websocket wss, acting exactly the |
| 72 | same. |
| 73 | |
Andy Green | b214977 | 2010-10-31 13:15:56 +0000 | [diff] [blame] | 74 | test-server.c is all that is needed to use libwebsockets for |
| 75 | serving both the script html over http and websockets. |
| 76 | |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 77 | |
Andy Green | ed11a02 | 2011-01-20 10:23:50 +0000 | [diff] [blame] | 78 | Forkless operation |
| 79 | ------------------ |
| 80 | |
| 81 | If your target device does not offer fork(), you can use |
| 82 | libwebsockets from your own main loop instead. Use the |
| 83 | configure option --nofork and simply call libwebsocket_service() |
| 84 | from your own main loop as shown in the test app sources. |
| 85 | |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 86 | |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 87 | Testing websocket client support |
| 88 | -------------------------------- |
| 89 | |
| 90 | If you run the test server as described above, you can also |
| 91 | connect to it using the test client as well as a browser. |
| 92 | |
| 93 | $ libwebsockets-test-client localhost |
| 94 | |
| 95 | will by default connect to the test server on localhost:7681 |
| 96 | and print the dumb increment number from the server at the |
| 97 | same time as drawing random circles in the mirror protocol; |
| 98 | if you connect to the test server using a browser at the |
| 99 | same time you will be able to see the circles being drawn. |
| 100 | |
Andy Green | ed11a02 | 2011-01-20 10:23:50 +0000 | [diff] [blame] | 101 | |
Andy Green | 90c7cbc | 2011-01-27 06:26:52 +0000 | [diff] [blame] | 102 | Testing SSL on the client side |
| 103 | ------------------------------ |
| 104 | |
| 105 | To test SSL/WSS client action, just run the client test with |
| 106 | |
| 107 | $ libwebsockets-test-client localhost --ssl |
| 108 | |
| 109 | By default the client test applet is set to accept selfsigned |
| 110 | certificates used by the test server, this is indicated by the |
| 111 | use_ssl var being set to 2. Set it to 1 to reject any server |
| 112 | certificate that it doesn't have a trusted CA cert for. |
| 113 | |
| 114 | |
Andy Green | a6cbece | 2011-01-27 20:06:03 +0000 | [diff] [blame] | 115 | Using the websocket ping utility |
| 116 | -------------------------------- |
| 117 | |
| 118 | libwebsockets-test-ping connects as a client to a remote |
| 119 | websocket server using 04 protocol and pings it like the |
| 120 | normal unix ping utility. |
| 121 | |
| 122 | $ libwebsockets-test-ping localhost |
| 123 | handshake OK for protocol lws-mirror-protocol |
| 124 | Websocket PING localhost.localdomain (127.0.0.1) 64 bytes of data. |
| 125 | 64 bytes from localhost: req=1 time=0.1ms |
| 126 | 64 bytes from localhost: req=2 time=0.1ms |
| 127 | 64 bytes from localhost: req=3 time=0.1ms |
| 128 | 64 bytes from localhost: req=4 time=0.2ms |
| 129 | 64 bytes from localhost: req=5 time=0.1ms |
| 130 | 64 bytes from localhost: req=6 time=0.2ms |
| 131 | 64 bytes from localhost: req=7 time=0.2ms |
| 132 | 64 bytes from localhost: req=8 time=0.1ms |
| 133 | ^C |
| 134 | --- localhost.localdomain websocket ping statistics --- |
| 135 | 8 packets transmitted, 8 received, 0% packet loss, time 7458ms |
| 136 | rtt min/avg/max = 0.110/0.185/0.218 ms |
| 137 | $ |
| 138 | |
| 139 | By default it sends 64 byte payload packets using the 04 |
| 140 | PING packet opcode type. You can change the payload size |
| 141 | using the -s= flag, up to a maximum of 125 mandated by the |
| 142 | 04 standard. |
| 143 | |
| 144 | Using the lws-mirror protocol that is provided by the test |
| 145 | server, libwebsockets-test-ping can also use larger payload |
| 146 | sizes up to 4096 is BINARY packets; lws-mirror will copy |
| 147 | them back to the client and they appear as a PONG. Use the |
| 148 | -m flag to select this operation. |
| 149 | |
| 150 | The default interval between pings is 1s, you can use the -i= |
| 151 | flag to set this, including fractions like -i=0.01 for 10ms |
| 152 | interval. |
| 153 | |
| 154 | Before you can even use the PING opcode that is part of the |
| 155 | standard, you must complete a handshake with a specified |
| 156 | protocol. By default lws-mirror-protocol is used which is |
| 157 | supported by the test server. But if you are using it on |
| 158 | another server, you can specify the protcol to handshake with |
| 159 | by --protocol=protocolname |
| 160 | |
| 161 | |
Andy Green | 9659f37 | 2011-01-27 22:01:43 +0000 | [diff] [blame] | 162 | proxy support |
| 163 | ------------- |
| 164 | |
| 165 | The http_proxy environment variable is respected by the client |
| 166 | connection code for both ws:// and wss://. It doesn't support |
| 167 | authentication yet. |
| 168 | |
| 169 | You use it like this |
| 170 | |
| 171 | export http_proxy=myproxy.com:3128 |
| 172 | libwebsockets-test-client someserver.com |
| 173 | |
| 174 | |
Andy Green | ed11a02 | 2011-01-20 10:23:50 +0000 | [diff] [blame] | 175 | Websocket version supported |
| 176 | --------------------------- |
| 177 | |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 178 | The websocket client code is 04 version, the server supports |
| 179 | both 00/76 in text mode and 04 dynamically per-connection |
| 180 | depending on the version of the client / browser. |
Andy Green | ed11a02 | 2011-01-20 10:23:50 +0000 | [diff] [blame] | 181 | |
Andy Green | 4739e5c | 2011-01-22 12:51:57 +0000 | [diff] [blame] | 182 | 2011-01-22 Andy Green <andy@warmcat.com> |
Andy Green | b214977 | 2010-10-31 13:15:56 +0000 | [diff] [blame] | 183 | |