1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
.. _websocket_examples:
WebSocket Examples
==================
Basic Examples
--------------
.. note::
The examples here demonstrate WebSocket programming with |ab| and are available in Twisted and asyncio-based variants respectively.
Echo
....
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo>`__ / `asyncio <https://github.com/crossbario/autobahn-python/blob/master/examples/asyncio/websocket/echo>`__
A simple WebSocket echo server and client.
Slow Square
............
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/slowsquare>`__ / `asyncio <https://github.com/crossbario/autobahn-python/blob/master/examples/asyncio/websocket/slowsquare>`__
This example shows a WebSocket server that will receive a JSON encode float over WebSocket, slowly compute the square, and send back the result.
The example is intended to demonstrate how to use co-routines inside WebSocket handlers.
Testee
......
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/testee>`__ / `asyncio <https://github.com/crossbario/autobahn-python/blob/master/examples/asyncio/websocket/testee>`__
The example implements a *testee* for testing against `Autobahn|Testsuite <http://crossbar.io/autobahn#testsuite>`_.
-----------
Additional Examples
-------------------
.. note::
The examples here demonstrate various further features and aspects of WebSocket programming with |ab|. However, these examples are **currently only available for Twisted**.
Secure WebSocket
................
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_tls>`__
How to run WebSocket over TLS ("wss").
WebSocket and Twisted Web
.........................
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_site>`__
How to run WebSocket under Twisted Web. This is a very powerful feature, as it allows you to create a complete HTTP(S) resource hierarchy with different services like static file serving, REST and WebSocket combined under one server.
Twisted Web, WebSocket and WSGI
...............................
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_wsgi>`__
This example shows how to run Flask (or any other WSGI compliant Web thing) under Twisted Web and combine that with WebSocket.
Secure WebSocket and Twisted Web
................................
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_site_tls>`__
A variant of the previous example that runs a HTTPS server with secure WebSocket on a subpath.
WebSocket Ping-Pong
...................
`Twisted <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/ping>`__
The example demonstrates how to trigger and process WebSocket pings and pongs.
More
....
* `WebSocket Authentication with Mozilla Persona <https://github.com/crossbario/autobahn-python/tree/master/examples/twisted/websocket/auth_persona>`_
* `Broadcasting over WebSocket <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/broadcast>`_
* `WebSocket Compression <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_compressed>`_
* `WebSocket over Twisted Endpoints <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_endpoints>`_
* `Using HTTP Headers with WebSocket <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_httpheaders>`_
* `WebSocket on Multicore <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_multicore>`_
* `WebSocket as a Twisted Service <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_service>`_
* `WebSocket Echo Variants <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_variants>`_
* `WebSocket Fallbacks <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/echo_wsfallbacks>`_
* `Using multiple WebSocket Protocols <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/multiproto>`_
* `Streaming WebSocket <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/streaming>`_
* `Wrapping Twisted Protocol/Factories over WebSocket <https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/websocket/wrapping>`_
* `Using wxPython with Autobahn <https://github.com/crossbario/autobahn-python/tree/master/examples/twisted/websocket/wxpython>`_
|