mco_lews_websocket_negotiation_response

Prototype

    MCO_RET mco_lews_websocket_negotiation_response(lews_connection_context_h ctx);

Arguments

ctx
Handle to the connection context containing a valid WebSocket upgrade request.

Description

This function completes the WebSocket handshake by generating and sending the HTTP 101 Switching Protocols response to the client.

It computes the required Sec-WebSocket-Accept header based on the value of the client’s Sec-WebSocket-Key, as specified in RFC 6455, and sends the full upgrade response.

The function should only be called after confirming that the incoming request is a WebSocket upgrade request (e.g., using mco_lews_is_websocket_request()).

    ...
    if (IS_URL(p_ctx, "/ws")) {
        if (mco_lews_is_websocket_request(p_ctx)) {
            if (MCO_S_OK != mco_lews_websocket_negotiation_response(p_ctx)) {
                printf("mco_lews_websocket_negotiation_response error %d", ret);
                return;
            }
            // send data
            ...
        }
    }

Return Codes

MCO_S_OK
WebSocket handshake response successfully sent to the client.
MCO_E_NW_SENDERR
An error occurred while transmitting the handshake response over the network.
Other error codes
Indicate a system or internal error (e.g., socket failure, insufficient buffer space, etc.).

Files

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