Share this page

# web_websocket_send

Sends a message over a WebSocket connection.

## C Language

    int web_websocket_send("ID=connection ID", ["Buffer=message_Text",] ["Buffer/BIN=message_Text",]  ["Buffer/File=file",] "IsBinary=0/1", LAST);

Miscellaneous Functions

ID | The ID of the connection over which to send the message.
Buffer | The string to send to the server.
Buffer/BIN | The binary representation of the string to send to the server. Note: At least one of the arguments Buffer or Buffer/BIN must be present.
Buffer/File | The pathname or UNC path of the file to send. If the file is stored in the script directory, pass the filename. For example, "`c:\myfolder\myfile.txt`", "\\mymachine\mysharedfolder\myfile.txt"
IsBinary | Indicates if the message sent by the API is binary (1, yes, true, or on) or text (0, no, false, or off). Note: The message string is converted as indicated by this argument. For example, for web_websocket_send( “ID=0”, “Buffer/BIN=\x61\x62\x63\x64\x65”, “IsBinary=0”, LAST), the buffer is sent as text.
LAST | Required marker for the end of the argument list.

This function sends the contents of the specified buffer or the specified file to the server with the specified ID, using the WebSocket protocol.

To see runtime or post-run statistics generated by this function, use the WebSocket Statistics monitor under the Web Resource graphs. You access this graph from the Controller Run tab. The graph shows the following measurements: New Connections per second, Bytes Sent per second, Bytes Received per second, and Failed Connections per second.

You can add lr_think_time calls between web_websocket_send steps to allow the protocol to complete send and receive operations.

If this function fails, it triggers an onErrorCB callback. For a list of the callback functions, see WebSocket Callback Functions.

## Return Values

This function returns LR_PASS (0) on success, and LR_FAIL (1) on failure.

## Parameterization

Standard Parameterization is supported for all of this function's arguments.

## Example

In the following example, the Vuser creates a WebSocket, sends a message, and then closes it.

    #include "as_web.h"

    Action()
    {
    web_websocket_connect("ID=0", "URI=ws://pumpkin:9876/", "Origin=http://pumpkin:9876", "OnOpenCB=OnOpenCB0", "OnMessageCB=OnMessageCB0", "OnErrorCB=OnErrorCB0", "OnCloseCB=OnCloseCB0", LAST);
    web_websocket_send("ID=0", "Buffer=sample text message", "IsBinary=0", LAST);
    web_websocket_send("ID=0", "Buffer/File={myfile}", "IsBinary=0", LAST);
    /*Connection ID 0 received buffer WebSocketReceive0*/
    lr_think_time(7);
    web_websocket_close("ID=0", "Code=1000", "Reason=OK", LAST);
    return 0;
    }

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