Close the WebSocket connection. Optionally specify a `code` (`int`) and a `reason` (`str`) for closing the connection. ```python # Normal close. ws.close() # Close with code and reason. ws.close(code=1000, reason="Task completed") ``
(self, code=None, reason=None)
| 272 | self._js_websocket.send(buffer) |
| 273 | |
| 274 | def close(self, code=None, reason=None): |
| 275 | """ |
| 276 | Close the WebSocket connection. Optionally specify a `code` (`int`) |
| 277 | and a `reason` (`str`) for closing the connection. |
| 278 | |
| 279 | ```python |
| 280 | # Normal close. |
| 281 | ws.close() |
| 282 | |
| 283 | # Close with code and reason. |
| 284 | ws.close(code=1000, reason="Task completed") |
| 285 | ``` |
| 286 | |
| 287 | Usage and values for `code` and `reasons` |
| 288 | [are explained here](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/close). |
| 289 | """ |
| 290 | if code and reason: |
| 291 | self._js_websocket.close(code, reason) |
| 292 | elif code: |
| 293 | self._js_websocket.close(code) |
| 294 | else: |
| 295 | self._js_websocket.close() |
no outgoing calls