ws_get_status - get client’s connection status#
-
enum ws_status ws_get_status(struct websockets *ws)#
Returns the WebSockets handle connection status.
- Parameters:
ws – the WebSockets handle created with ws_init()
- Returns:
a ws_status opcode
Wrappers#
-
ws_is_alive(ws) (ws_get_status(ws) != WS_DISCONNECTED)#
Check if a WebSockets connection is alive.
This will only return true if the connection status is different than WS_DISCONNECTED
- Parameters:
ws – the WebSockets handle created with ws_init()
- Returns:
trueif WebSockets status is different than WS_DISCONNECTED,falseotherwise.
-
ws_is_functional(ws) (ws_get_status(ws) == WS_CONNECTED)#
Check if WebSockets connection is functional.
This will only return true if the connection status is WS_CONNECTED
- Parameters:
ws – the WebSockets handle created with ws_init()
- Returns:
trueif is functional,falseotherwise
Example#
CURLM *mhandle = curl_multi_init();
struct websockets *ws = ws_init(&cbs, mhandle, NULL);
ws_set_url(ws, "wss://example.com", NULL);
/* run the event-loop */
ws_start(ws);
uint64_t tstamp;
bool is_running;
do {
is_running = ws_easy_run(ws, 5, &tstamp);
if (WS_CONNECTING == ws_get_status(ws)) {
/* do something */
}
} while (is_running);
ws_end(ws);
ws_cleanup(ws);
curl_multi_cleanup(mhandle);