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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
API
===
Design
------
``websockets`` provides complete client and server implementations, as shown
in the :doc:`getting started guide <intro>`. These functions are built on top
of low-level APIs reflecting the two phases of the WebSocket protocol:
1. An opening handshake, in the form of an HTTP Upgrade request;
2. Data transfer, as framed messages, ending with a closing handshake.
The first phase is designed to integrate with existing HTTP software.
``websockets`` provides a minimal implementation to build, parse and validate
HTTP requests and responses.
The second phase is the core of the WebSocket protocol. ``websockets``
provides a complete implementation on top of ``asyncio`` with a simple API.
For convenience, public APIs can be imported directly from the
:mod:`websockets` package, unless noted otherwise. Anything that isn't listed
in this document is a private API.
High-level
----------
Server
......
.. automodule:: websockets.server
.. autofunction:: serve(ws_handler, host=None, port=None, *, create_protocol=None, 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, loop=None, compression='deflate', origins=None, extensions=None, subprotocols=None, extra_headers=None, process_request=None, select_subprotocol=None, **kwds)
:async:
.. autofunction:: unix_serve(ws_handler, path, *, create_protocol=None, 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, loop=None, compression='deflate', origins=None, extensions=None, subprotocols=None, extra_headers=None, process_request=None, select_subprotocol=None, **kwds)
:async:
.. autoclass:: WebSocketServer
.. automethod:: close
.. automethod:: wait_closed
.. autoattribute:: sockets
.. autoclass:: WebSocketServerProtocol(ws_handler, ws_server, *, 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, loop=None, origins=None, extensions=None, subprotocols=None, extra_headers=None, process_request=None, select_subprotocol=None)
.. automethod:: handshake
.. automethod:: process_request
.. automethod:: select_subprotocol
Client
......
.. automodule:: websockets.client
.. autofunction:: connect(uri, *, create_protocol=None, 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, loop=None, compression='deflate', origin=None, extensions=None, subprotocols=None, extra_headers=None, **kwds)
:async:
.. autofunction:: unix_connect(path, uri="ws://localhost/", *, create_protocol=None, 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, loop=None, compression='deflate', origin=None, extensions=None, subprotocols=None, extra_headers=None, **kwds)
:async:
.. autoclass:: WebSocketClientProtocol(*, 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, loop=None, origin=None, extensions=None, subprotocols=None, extra_headers=None)
.. automethod:: handshake
Shared
......
.. automodule:: websockets.protocol
.. autoclass:: WebSocketCommonProtocol(*, 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, loop=None)
.. automethod:: close
.. automethod:: wait_closed
.. automethod:: recv
.. automethod:: send
.. automethod:: ping
.. automethod:: pong
.. autoattribute:: local_address
.. autoattribute:: remote_address
.. autoattribute:: open
.. autoattribute:: closed
Types
.....
.. automodule:: websockets.typing
.. autodata:: Data
Per-Message Deflate Extension
.............................
.. automodule:: websockets.extensions.permessage_deflate
.. autoclass:: ServerPerMessageDeflateFactory
.. autoclass:: ClientPerMessageDeflateFactory
HTTP Basic Auth
...............
.. automodule:: websockets.auth
.. autofunction:: basic_auth_protocol_factory
.. autoclass:: BasicAuthWebSocketServerProtocol
.. automethod:: process_request
Exceptions
..........
.. automodule:: websockets.exceptions
:members:
Low-level
---------
Opening handshake
.................
.. automodule:: websockets.handshake
:members:
Data transfer
.............
.. automodule:: websockets.framing
:members:
URI parser
..........
.. automodule:: websockets.uri
:members:
Utilities
.........
.. automodule:: websockets.headers
:members:
.. automodule:: websockets.http
:members:
|