WebSocket Protocol Guide
Use this guide when long-lived WebSocket sessions, message matching, or realtime channels need to be part of a performance or transaction test.
Matching docs
Search across docs titles, summaries, groups, and section headings.
Use Up and Down Arrow to move through results, then press Enter to open the active page.
No indexed docs matched that search. Try a broader term or open the docs hub.
What this page helps you do
What this page helps you do
Use this guide when long-lived WebSocket sessions, message matching, or realtime channels need to be part of a performance or transaction test.
Who this is for
Teams deciding how a protocol or browser runtime should fit inside one transaction-aware scenario.
Prerequisites
- A transport or browser flow that already matters to the workload
By the end
A clearer protocol-specific path that still fits the same scenario and reporting model.
Use this page when
Use this page when WebSocket Protocol Guide belongs inside the transaction story and you need the supported path into the same scenario model.
Visual guide
Guide
What This Guide Covers
Use this guide when a WebSocket connection is the source, destination, or observed channel in the workflow. LoadStrike supports ws:// and wss:// endpoint configuration, subprotocols, headers, connect and close timeouts, text and binary message specifications, expected-message matching, reconnect policy, ping/pong tracking, close-code tracking, message latency, throughput, and byte metrics where supported by the SDK runtime.
Long-Lived Sessions
WebSocket scenarios often care about more than one request. Model the connect, send, receive, and close behavior explicitly so reports can show message latency, connection duration, reconnects, receive timeouts, and protocol failures beside normal scenario counts.
Native Or Delegate-Backed
Use native WebSocket options when the SDK can own the socket flow directly. Use delegate-backed endpoints when the application client, authentication flow, or message codec already exists in your test project. Both options stay inside the same LoadStrike runner, portal, local report, and sink lifecycle.
Plan Gate
WebSocket endpoint support is available on Pro and above. Runs still validate any extra features used by the scenario, such as portal reporting, sinks, thresholds, or distributed cluster settings.
Protocol setup samples
Use these samples to compare native and delegate-backed WebSocket endpoint setup across the supported SDKs.
If you run these examples locally, add a valid runner key before execution starts. Set it with WithRunnerKey("...") or the config key LoadStrike:RunnerKey.
WebSocket Protocol Setup
using LoadStrike;
using LoadStrike.CrossPlatform;
using LoadStrike.CrossPlatform.WebSockets;
var endpoint = new WebSocketEndpointDefinition
{
Name = "orders-websocket",
Mode = TrafficEndpointMode.Produce,
TrackingField = TrackingFieldSelector.Parse("header:x-tracking-id"),
Url = "wss://realtime.example.com/orders",
Subprotocols = ["orders.v1"],
MessageHeaders = new Dictionary<string, string>
{
["x-tracking-id"] = "ord-1001"
},
NativeClient = new WebSocketNativeClientOptions
{
Messages =
[
WebSocketMessageSpec.Text("{\"type\":\"subscribe\",\"orderId\":\"ord-1001\"}")
],
ExpectedMessages =
[
new WebSocketExpectedMessage
{
ContainsText = "ord-1001",
Timeout = TimeSpan.FromSeconds(10)
}
]
}
};
_ = endpoint;
package main
import (
"context"
loadstrike "loadstrike.com/sdk/go"
)
var webSocketEndpoint = &loadstrike.EndpointSpec{
Kind: "WebSocket",
Name: "orders-websocket",
Mode: "Consume",
TrackingField: "json:$.trackingId",
WebSocket: &loadstrike.WebSocketEndpointOptions{
URL: "wss://realtime.example.com/orders",
Subprotocols: []string{"orders.v1"},
Consume: func(_ context.Context, onMessage func(loadstrike.EndpointConsumeEvent) error) error {
return onMessage(loadstrike.EndpointConsumeEvent{
TrackingID: "ord-1001",
Payload: loadstrike.TrackingPayload{
Body: map[string]any{"trackingId": "ord-1001", "status": "completed"},
},
})
},
},
}
import java.util.Map;
import com.loadstrike.runtime.LoadStrikeCorrelation.TrackingFieldSelector;
import com.loadstrike.runtime.LoadStrikeCorrelation.TrackingPayload;
import com.loadstrike.runtime.LoadStrikeTransports;
import com.loadstrike.runtime.LoadStrikeTransports.ConsumedMessage;
import com.loadstrike.runtime.WebSocketEndpointDefinition;
var endpoint = new WebSocketEndpointDefinition();
endpoint.name = "orders-websocket";
endpoint.mode = LoadStrikeTransports.TrafficEndpointMode.Consume;
endpoint.trackingField = TrackingFieldSelector.parse("json:$.trackingId");
endpoint.url = "wss://realtime.example.com/orders";
endpoint.subprotocols = java.util.List.of("orders.v1");
endpoint.consumeAsync = () -> {
var message = new ConsumedMessage();
message.payload = new TrackingPayload(
Map.of(),
Map.of("trackingId", "ord-1001", "status", "completed"),
(String) null);
return message;
};
from loadstrike_sdk import WebSocketEndpointDefinition
endpoint = WebSocketEndpointDefinition(
name="orders-websocket",
mode="Consume",
tracking_field="json:$.trackingId",
url="wss://realtime.example.com/orders",
subprotocols=["orders.v1"],
consume_async=lambda on_message: on_message({
"Payload": {"Body": {"trackingId": "ord-1001", "status": "completed"}}
}),
)
import { WebSocketEndpointDefinition } from "@loadstrike/loadstrike-sdk";
const endpoint = new WebSocketEndpointDefinition({
Name: "orders-websocket",
Mode: "Consume",
TrackingField: "json:$.trackingId",
Url: "wss://realtime.example.com/orders",
Subprotocols: ["orders.v1"],
ConsumeAsync: async (onMessage) => {
await onMessage({ payload: { body: { trackingId: "ord-1001", status: "completed" } } });
}
});
void endpoint;
const { WebSocketEndpointDefinition } = require("@loadstrike/loadstrike-sdk");
const endpoint = new WebSocketEndpointDefinition({
Name: "orders-websocket",
Mode: "Consume",
TrackingField: "json:$.trackingId",
Url: "wss://realtime.example.com/orders",
Subprotocols: ["orders.v1"],
ConsumeAsync: async (onMessage) => {
await onMessage({ payload: { body: { trackingId: "ord-1001", status: "completed" } } });
}
});
void endpoint;
Goal
Use an absolute ws:// or wss:// endpoint for the realtime channel under test.
Keep a stable tracking value in text, binary, header, or JSON payload data so LoadStrike can match the workflow.
Track receive latency, reconnect behavior, close codes, and message volume alongside scenario results.