| 1 |
Server (:mod:`threading`) |
| 2 |
========================= |
| 3 |
|
| 4 |
.. automodule:: websockets.sync.server |
| 5 |
|
| 6 |
Creating a server |
| 7 |
----------------- |
| 8 |
|
| 9 |
.. autofunction:: serve |
| 10 |
|
| 11 |
.. autofunction:: unix_serve |
| 12 |
|
| 13 |
Routing connections |
| 14 |
------------------- |
| 15 |
|
| 16 |
.. automodule:: websockets.sync.router |
| 17 |
|
| 18 |
.. autofunction:: route |
| 19 |
|
| 20 |
.. autofunction:: unix_route |
| 21 |
|
| 22 |
.. autoclass:: Router |
| 23 |
|
| 24 |
.. currentmodule:: websockets.sync.server |
| 25 |
|
| 26 |
Running a server |
| 27 |
---------------- |
| 28 |
|
| 29 |
.. autoclass:: Server |
| 30 |
|
| 31 |
.. autoattribute:: connections |
| 32 |
|
| 33 |
.. automethod:: serve_forever |
| 34 |
|
| 35 |
.. automethod:: shutdown |
| 36 |
|
| 37 |
.. automethod:: fileno |
| 38 |
|
| 39 |
Using a connection |
| 40 |
------------------ |
| 41 |
|
| 42 |
.. autoclass:: ServerConnection |
| 43 |
|
| 44 |
.. automethod:: respond |
| 45 |
|
| 46 |
.. automethod:: __iter__ |
| 47 |
|
| 48 |
.. automethod:: recv |
| 49 |
|
| 50 |
.. automethod:: recv_streaming |
| 51 |
|
| 52 |
.. automethod:: send |
| 53 |
|
| 54 |
.. automethod:: close |
| 55 |
|
| 56 |
.. automethod:: ping |
| 57 |
|
| 58 |
.. automethod:: pong |
| 59 |
|
| 60 |
WebSocket connection objects also provide these attributes: |
| 61 |
|
| 62 |
.. autoattribute:: id |
| 63 |
|
| 64 |
.. autoattribute:: logger |
| 65 |
|
| 66 |
.. autoproperty:: local_address |
| 67 |
|
| 68 |
.. autoproperty:: remote_address |
| 69 |
|
| 70 |
.. autoattribute:: latency |
| 71 |
|
| 72 |
.. autoproperty:: state |
| 73 |
|
| 74 |
The following attributes are available after the opening handshake, |
| 75 |
once the WebSocket connection is open: |
| 76 |
|
| 77 |
.. autoattribute:: request |
| 78 |
|
| 79 |
.. autoattribute:: response |
| 80 |
|
| 81 |
.. autoproperty:: subprotocol |
| 82 |
|
| 83 |
The following attributes are available after the closing handshake, |
| 84 |
once the WebSocket connection is closed: |
| 85 |
|
| 86 |
.. autoproperty:: close_code |
| 87 |
|
| 88 |
.. autoproperty:: close_reason |
| 89 |
|
| 90 |
Broadcast |
| 91 |
--------- |
| 92 |
|
| 93 |
.. autofunction:: broadcast |
| 94 |
|
| 95 |
HTTP Basic Authentication |
| 96 |
------------------------- |
| 97 |
|
| 98 |
websockets supports HTTP Basic Authentication according to |
| 99 |
:rfc:`7235` and :rfc:`7617`. |
| 100 |
|
| 101 |
.. autofunction:: basic_auth |