diff options
author | engn33r <engn33r@users.noreply.github.com> | 2022-10-26 01:08:31 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-26 01:08:31 +0000 |
commit | 57cc86b07cb3bad34721106e79f95e145507ca4e (patch) | |
tree | 5c6f7708c2c62e2c2a4fe54dc53146318cbfe8c7 | |
parent | b33897cbb03f320fd5df7ec28ef92daadf1ce366 (diff) | |
download | websocket-client-57cc86b07cb3bad34721106e79f95e145507ca4e.tar.gz |
Update docs to fix #863 (#872)
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | docs/source/examples.rst | 4 | ||||
-rw-r--r-- | websocket/_app.py | 8 |
3 files changed, 19 insertions, 8 deletions
@@ -73,10 +73,17 @@ Many more examples are found in the Most real-world WebSockets situations involve longer-lived connections. The WebSocketApp `run_forever` loop will automatically try to reconnect to an open WebSocket connection when a network -connection is lost if it is provided with a dispatcher parameter, -and provides a variety of event-based connection controls. +connection is lost if it is provided with: + +- a `dispatcher` argument (async dispatcher like rel or pyevent) +- a non-zero `reconnect` argument (delay between disconnection and attempted reconnection) + +`run_forever` provides a variety of event-based connection controls +using callbacks like `on_message` and `on_error`. `run_forever` does not automatically reconnect if the server -closes the WebSocket. Customizing behavior when the server closes +closes the WebSocket gracefully (returning +[a standard websocket close code](https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1)). +Customizing behavior when the server closes the WebSocket should be handled in the `on_close` callback. This example uses [rel](https://github.com/bubbleboy14/registeredeventlistener) for the dispatcher to provide automatic reconnection. @@ -107,7 +114,7 @@ if __name__ == "__main__": on_error=on_error, on_close=on_close) - ws.run_forever(dispatcher=rel) # Set dispatcher to automatic reconnection + ws.run_forever(dispatcher=rel, reconnect=5) # Set dispatcher to automatic reconnection, 5 second reconnect delay if connection closed unexpectedly rel.signal(2, rel.abort) # Keyboard Interrupt rel.dispatch() ``` diff --git a/docs/source/examples.rst b/docs/source/examples.rst index d3d5b99..9b3a905 100644 --- a/docs/source/examples.rst +++ b/docs/source/examples.rst @@ -700,7 +700,7 @@ You can use an asynchronous dispatcher such as `rel <https://pypi.org/project/re >>> addr = "wss://api.gemini.com/v1/marketdata/%s" >>> for symbol in ["BTCUSD", "ETHUSD", "ETHBTC"]: ... ws = websocket.WebSocketApp(addr % (symbol,), on_message=lambda w, m : print(m)) - ... ws.run_forever(dispatcher=rel) # doctest: +SKIP + ... ws.run_forever(dispatcher=rel, reconnect=3) # doctest: +SKIP >>> rel.signal(2, rel.abort) # Keyboard Interrupt # doctest: +SKIP >>> rel.dispatch() # doctest: +SKIP @@ -739,7 +739,7 @@ The examples are found in the README and are copied here for sphinx doctests to ... on_error=on_error, ... on_close=on_close) - >>> ws.run_forever(dispatcher=rel) # Set dispatcher to automatic reconnection # doctest: +SKIP + >>> ws.run_forever(dispatcher=rel, reconnect=5) # Set dispatcher to automatic reconnection, 5 second reconnect delay if connection closed unexpectedly # doctest: +SKIP >>> rel.signal(2, rel.abort) # Keyboard Interrupt <Signal Object | Callback:"abort"> >>> rel.dispatch() # doctest: +SKIP diff --git a/websocket/_app.py b/websocket/_app.py index 67d253c..20bcbfe 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -287,12 +287,12 @@ class WebSocketApp: HTTP proxy host name. http_proxy_port: int or str HTTP proxy port. If not set, set to 80. + http_no_proxy: list + Whitelisted host names that don't use the proxy. http_proxy_timeout: int or float HTTP proxy timeout, default is 60 sec as per python-socks. http_proxy_auth: tuple HTTP proxy auth information. tuple of username and password. Default is None. - http_no_proxy: list - Whitelisted host names that don't use the proxy. skip_utf8_validation: bool skip utf8 validation. host: str @@ -303,6 +303,10 @@ class WebSocketApp: customize reading data from socket. suppress_origin: bool suppress outputting origin header. + proxy_type: str + type of proxy from: http, socks4, socks4a, socks5, socks5h + reconnect: int + delay interval when reconnecting Returns ------- |