mco_lews_send_websocket_data_frame

Prototype

    MCO_RET mco_lews_send_websocket_data_frame(
        lews_connection_context_h ctx,
        const char *data,
        mco_size_t data_size,
        mco_bool is_text
    );

Arguments

ctx
Handle to the active connection context.
data
Pointer to the buffer containing the payload to send.
data_size
Size (in bytes) of the data to be sent.
is_text
Flag indicating the frame type: 1 for text, 0 for binary data.

Description

This function sends a WebSocket data frame over an established connection.

The data is automatically wrapped in a WebSocket frame with the appropriate opcode (TEXT or BINARY) based on the is_text flag.

The connection must already be upgraded to WebSocket via a successful handshake before calling this function.

    ...
    sz = snprintf(str_buf, sizeof(str_buf), "#%d Hello World", i);
    if (MCO_S_OK != mco_lews_send_websocket_data_frame(p_ctx, str_buf, sz, 1)) {
        printf("mco_lews_send_websocket_data_frame error %d\n", ret);
        return;
    }
    ...

Return Codes

MCO_S_OK
Data frame successfully sent to the client.
MCO_E_NW_SENDERR
An error occurred while transmitting the data over the network.
MCO_E_LEWS_NO_ENOUGH_MEMORY
The output buffer is too small to hold the WebSocket data frame (including the header).

Files

Header file:
mcoewslite.h
Source file:
mcoewslite.c
Library:
mcoewslite.a