Expand/Shrink

nopoll_conn_is_ok

Definition: include nopoll.e

bool ok = nopoll_conn_is_ok(atom conn)
Description: Check if the provided connection is in connected state (just to the connection).

conn: The websocket connection to be checked.

This is different to be ready to send and receive content because the session needs to be first established.

You can use nopoll_conn_is_ready() to ensure the connection is ready to be used (read or write operation can be done because handshake has finished).

For example, you might connect to a raw socket server and nopoll_conn_is_ok will report that everything is ok because the socket is indeed connected but because you are connecting to a non-websocket server, it will not work because the WebSocket session establishment didn’t take place and hence nopoll_conn_is_ready() will fail.

Returns: true in the case the connection is working otherwise false is returned.
Example:
include nopoll.e

atom ctx = nopoll_ctx_new()
atom conn = nopoll_conn_new(ctx, "echo.websocket.org", "80", NULL, "/", NULL, NULL)
if not nopoll_conn_is_ok(conn) then
    -- some error handling here
end if
if not nopoll_conn_wait_until_connection_ready(conn, 5) then
    -- some error handling
end if

if nopoll_conn_send_text(conn, "Hello there! this is a test", 27) != 27 then
    -- yet more error handling
end if

...
See Also: nopoll_conn_is_ready