web_websocket_connect
Creates a WebSocket connection.
C Language
int web_websocket_connect("ID=connection", "URI=ws://server:port", ["Origin=value ", SecWebSocketKey=value ", "SecWebSocketProtocol=value ", SecWebSocketExtensions=value, OnOpenCB=func_name, OnMessageCB=func_name, OnErrorCB=func_name, OnCloseCB=func_name, ] LAST);| Miscellaneous Functions |
| ID | A unique number indicating the connection number. This value is generated automatically during code generation. |
| URI | The WebSocket endpoint in ws:// or wss:// (secure WebSocket schema) format. |
| Origin | Origin header value. Optional: Only generated if detected during the recording session. |
| SecWebSocketKey | Sec-WebSocket-Key header value. Optional: The WebSocket key value. Not recorded, but can be added manually. |
| SecWebSocketProtocol | Sec-WebSocket-Protocol header value. Optional: Only generated if detected during the recording session. |
| SecWebSocketExtensions | Sec-WebSocket-Extensions header value. Optional: Only generated if detected during the recording session. |
| OnOpenCB | Callback function name for an OnOpen event (optional). |
| OnMessageCB | Callback function name for an OnMessage event (optional). |
| OnErrorCB | Callback function name for an OnError event (optional). |
| OnCloseCB | Callback function name for an OnClose event (optional). |
| LAST | Required marker for the end of the argument list. |
This function creates a WebSocket connection upon which to send the message.
Headers that were detected during recording will be generated automatically, except for SecWebSocketKey. To add additional headers to the handshake request, place web_add_header or web_add_cookie steps before this function.
Callbacks will be generated with the default implementation commented out. For a description 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;
}

