| 1 |
Server (legacy) |
| 2 |
=============== |
| 3 |
|
| 4 |
.. admonition:: The legacy :mod:`asyncio` implementation is deprecated. |
| 5 |
:class: caution |
| 6 |
|
| 7 |
The :doc:`upgrade guide <../../howto/upgrade>` provides complete instructions |
| 8 |
to migrate your application. |
| 9 |
|
| 10 |
.. automodule:: websockets.legacy.server |
| 11 |
|
| 12 |
Starting a server |
| 13 |
----------------- |
| 14 |
|
| 15 |
.. autofunction:: serve(ws_handler, host=None, port=None, *, create_protocol=None, logger=None, compression="deflate", origins=None, extensions=None, subprotocols=None, extra_headers=None, server_header="Python/x.y.z websockets/X.Y", process_request=None, select_subprotocol=None, open_timeout=10, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, **kwds) |
| 16 |
|
| 17 |
.. autofunction:: unix_serve(ws_handler, path=None, *, create_protocol=None, logger=None, compression="deflate", origins=None, extensions=None, subprotocols=None, extra_headers=None, server_header="Python/x.y.z websockets/X.Y", process_request=None, select_subprotocol=None, open_timeout=10, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, **kwds) |
| 18 |
|
| 19 |
Stopping a server |
| 20 |
----------------- |
| 21 |
|
| 22 |
.. autoclass:: WebSocketServer |
| 23 |
|
| 24 |
.. automethod:: close |
| 25 |
|
| 26 |
.. automethod:: wait_closed |
| 27 |
|
| 28 |
.. automethod:: get_loop |
| 29 |
|
| 30 |
.. automethod:: is_serving |
| 31 |
|
| 32 |
.. automethod:: start_serving |
| 33 |
|
| 34 |
.. automethod:: serve_forever |
| 35 |
|
| 36 |
.. autoattribute:: sockets |
| 37 |
|
| 38 |
Using a connection |
| 39 |
------------------ |
| 40 |
|
| 41 |
.. autoclass:: WebSocketServerProtocol(ws_handler, ws_server, *, logger=None, origins=None, extensions=None, subprotocols=None, extra_headers=None, server_header="Python/x.y.z websockets/X.Y", process_request=None, select_subprotocol=None, open_timeout=10, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16) |
| 42 |
|
| 43 |
.. automethod:: recv |
| 44 |
|
| 45 |
.. automethod:: send |
| 46 |
|
| 47 |
.. automethod:: close |
| 48 |
|
| 49 |
.. automethod:: wait_closed |
| 50 |
|
| 51 |
.. automethod:: ping |
| 52 |
|
| 53 |
.. automethod:: pong |
| 54 |
|
| 55 |
You can customize the opening handshake in a subclass by overriding these methods: |
| 56 |
|
| 57 |
.. automethod:: process_request |
| 58 |
|
| 59 |
.. automethod:: select_subprotocol |
| 60 |
|
| 61 |
WebSocket connection objects also provide these attributes: |
| 62 |
|
| 63 |
.. autoattribute:: id |
| 64 |
|
| 65 |
.. autoattribute:: logger |
| 66 |
|
| 67 |
.. autoproperty:: local_address |
| 68 |
|
| 69 |
.. autoproperty:: remote_address |
| 70 |
|
| 71 |
.. autoproperty:: open |
| 72 |
|
| 73 |
.. autoproperty:: closed |
| 74 |
|
| 75 |
.. autoattribute:: latency |
| 76 |
|
| 77 |
The following attributes are available after the opening handshake, |
| 78 |
once the WebSocket connection is open: |
| 79 |
|
| 80 |
.. autoattribute:: path |
| 81 |
|
| 82 |
.. autoattribute:: request_headers |
| 83 |
|
| 84 |
.. autoattribute:: response_headers |
| 85 |
|
| 86 |
.. autoattribute:: subprotocol |
| 87 |
|
| 88 |
The following attributes are available after the closing handshake, |
| 89 |
once the WebSocket connection is closed: |
| 90 |
|
| 91 |
.. autoproperty:: close_code |
| 92 |
|
| 93 |
.. autoproperty:: close_reason |
| 94 |
|
| 95 |
Broadcast |
| 96 |
--------- |
| 97 |
|
| 98 |
.. autofunction:: websockets.legacy.server.broadcast |
| 99 |
|
| 100 |
Basic authentication |
| 101 |
-------------------- |
| 102 |
|
| 103 |
.. automodule:: websockets.legacy.auth |
| 104 |
|
| 105 |
websockets supports HTTP Basic Authentication according to |
| 106 |
:rfc:`7235` and :rfc:`7617`. |
| 107 |
|
| 108 |
.. autofunction:: basic_auth_protocol_factory |
| 109 |
|
| 110 |
.. autoclass:: BasicAuthWebSocketServerProtocol |
| 111 |
|
| 112 |
.. autoattribute:: realm |
| 113 |
|
| 114 |
.. autoattribute:: username |
| 115 |
|
| 116 |
.. automethod:: check_credentials |