@@ -140,6 +140,19 @@ def remote_address(self) -> Any:
140
140
"""
141
141
return self .socket .getpeername ()
142
142
143
+ @property
144
+ def state (self ) -> State :
145
+ """
146
+ State of the WebSocket connection, defined in :rfc:`6455`.
147
+
148
+ This attribute is provided for completeness. Typical applications
149
+ shouldn't check its value. Instead, they should call :meth:`~recv` or
150
+ :meth:`send` and handle :exc:`~websockets.exceptions.ConnectionClosed`
151
+ exceptions.
152
+
153
+ """
154
+ return self .protocol .state
155
+
143
156
@property
144
157
def subprotocol (self ) -> Subprotocol | None :
145
158
"""
@@ -150,6 +163,30 @@ def subprotocol(self) -> Subprotocol | None:
150
163
"""
151
164
return self .protocol .subprotocol
152
165
166
+ @property
167
+ def close_code (self ) -> int | None :
168
+ """
169
+ State of the WebSocket connection, defined in :rfc:`6455`.
170
+
171
+ This attribute is provided for completeness. Typical applications
172
+ shouldn't check its value. Instead, they should inspect attributes
173
+ of :exc:`~websockets.exceptions.ConnectionClosed` exceptions.
174
+
175
+ """
176
+ return self .protocol .close_code
177
+
178
+ @property
179
+ def close_reason (self ) -> str | None :
180
+ """
181
+ State of the WebSocket connection, defined in :rfc:`6455`.
182
+
183
+ This attribute is provided for completeness. Typical applications
184
+ shouldn't check its value. Instead, they should inspect attributes
185
+ of :exc:`~websockets.exceptions.ConnectionClosed` exceptions.
186
+
187
+ """
188
+ return self .protocol .close_reason
189
+
153
190
# Public methods
154
191
155
192
def __enter__ (self ) -> Connection :
0 commit comments