class documentation
class WebSocketAsync:
Constructor: WebSocketAsync(uri, headers, timeout, callback, ...)
WebSocket implementation that runs in a separate thread.
| Method | __del__ |
Destructor to clean up resources. |
| Method | __init__ |
Initialize the async WebSocket client. |
| Method | clear |
Clear the last received data. |
| Method | close |
Close the WebSocket connection. |
| Method | connect |
Start the WebSocket connection in a separate thread. |
| Method | ping |
Send a ping to the WebSocket server. |
| Method | pong |
Send a pong to the WebSocket server. |
| Method | send |
Send data to the WebSocket server. |
| Property | error |
Get the last error message, if any. |
| Property | is |
Check if the WebSocket is connected. |
| Property | is |
Check if the WebSocket thread is running. |
| Property | last |
Get the last received data. |
| Method | __close |
Internal method to close the thread. |
| Method | _should |
Check if the operation should continue running. |
| Instance Variable | _callback |
Undocumented |
| Instance Variable | _current |
Undocumented |
| Instance Variable | _headers |
Undocumented |
| Instance Variable | _last |
Undocumented |
| Instance Variable | _lock |
Undocumented |
| Instance Variable | _running |
Undocumented |
| Instance Variable | _stack |
Undocumented |
| Instance Variable | _thread |
Undocumented |
| Instance Variable | _thread |
Undocumented |
| Instance Variable | _timeout |
Undocumented |
| Instance Variable | _uri |
Undocumented |
| Instance Variable | _ws |
Undocumented |
def __init__(self, uri:
str, headers: dict = None, timeout: float = 10.0, callback: callable = None, thread_manager=None, stack_size: int = 32 * 1024):
¶
Initialize the async WebSocket client.
| Parameters | |
uri:str | WebSocket URL (ws:// or wss://). |
headers:dict | Optional additional headers for the handshake. Defaults to None. |
timeout:float | Connection timeout in seconds. Defaults to 10.0. |
callback:callable | Function called with received data. Defaults to None. |
threadThreadManager | Manager for threaded connections. Defaults to None. |
stackint | Thread stack size in bytes. Defaults to 32768. |
Send a ping to the WebSocket server.
| Parameters | |
data:bytes | Ping payload. Defaults to b"". |
| Returns | |
bool | True if sent successfully. |
Send a pong to the WebSocket server.
| Parameters | |
data:bytes | Pong payload. Defaults to b"". |
| Returns | |
bool | True if sent successfully. |