Share this page

# WebSocket Callback Functions

The following callback APIs are called by the web websocket functions. For a complete listing, see Miscellaneous Functions.

## onOpenCB

void onOpenCB(const char* connectionid, AccumulatedHeadersStr, int AccumulatedHeadersLen)

Connectionid | The connection ID.
AccumulatedHeadersStr | The accumulated header string.
AccumulatedHeadersLen | The length of the header string.

This callback is triggered when the WebSocket connection's readyState changes to OPEN. This indicates that the connection is ready.

## onMessageCB

void onMessageCB(const char* connectionid, int isbinary, char *data, int length)

Connectionid | The connection id.
isbinary | An indicator whether the string is binary or text.
Data | The buffer received from the server.
Data Length | The length of the buffer.

This callback is triggered when a message is received from the server.

## onCloseCB

void onCloseCB(const char* connectionid, int isClosedByClient, int code, const char* reason, int length)

Connectionid | The connection id.
isClosedByClient | An indicator whether the connection was closed by the client.
code | A 4-digit close code.
Reason | A string indicating the reason of the closure.
Length | The length of the reason message (0 for NULL).

This callback is triggered when the connection to the server is closed.

## onErrorCB

void onErrorCB(const char* connectionid, message, int length)

Connectionid | The connection id.
Message | The message of the error event (may be NULL).
Length | The length of the error message (0 for NULL).

This callback is triggered when an error is received from the server.

## Example

    function OnOpenCB0(){
        lr.logMessage('In function:' + arguments.callee);
        for(var key in arguments){
            lr.logMessage( 'arguments[' + key + ']=' + arguments[key] );
        }
    }

    function OnErrorCB0(){
        lr.logMessage('In function:' + arguments.callee);
        for(var key in arguments){
            lr.logMessage( 'arguments[' + key + ']=' + arguments[key] );
        }
    }

    function Action()
    {
        web.websocketConnect({
           id:'0',
           uri:'ws://echo.websocket.org',
           origin:'https://www.websocket.org/echo.html',
           onOpenCB: 'OnOpenCB0',
           onErrorCB:'OnErrorCB0'
         });

        return lr.pass
    }

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: