Skip to main content

HCWebSocketConnectFunction

Connects a WebSocket when you replace the libHttpClient WebSocket implementation. libHttpClient calls this callback when the title calls HCWebSocketConnectAsync.

Syntax

Parameters

uri   _In_z_
Type: const char*
The UTF-8 encoded URI to connect to. subProtocol   _In_z_
Type: const char*
The UTF-8 encoded subprotocol to request. websocket   _In_
Type: HCWebsocketHandle
The handle of the WebSocket. Use this handle with the provider functions, such as HCWebSocketGetHeaderAtIndex, HCWebSocketGetProxyUri, and HCWebSocketGetPingInterval. asyncBlock   _Inout_
Type: XAsyncBlock*
The async block for the connect operation. context   _In_opt_
Type: void*
The context value that you passed to HCSetWebSocketFunctions. env   _In_opt_
Type: HCPerformEnv
An opaque value reserved for the default implementation. Ignore it.

Return value

Type: HRESULT Return S_OK if the connect operation started. If you return a failure code, the connect operation fails with that code.

Remarks

Register this callback, together with the other three WebSocket callbacks, by calling HCSetWebSocketFunctions before HCInitialize. HCSetWebSocketFunctions requires all four callbacks; it returns E_INVALIDARG if any of them is nullptr. libHttpClient reads the result of the connect operation by calling HCGetWebSocketConnectResult on asyncBlock. That function retrieves a WebSocketCompletionResult by calling XAsyncGetResult with HCWebSocketConnectAsync as the identity. Your implementation must therefore do the following:
  1. Call XAsyncBegin on asyncBlock with HCWebSocketConnectAsync as the identity.
  2. When the connection attempt finishes, call XAsyncComplete(asyncBlock, hr, sizeof(WebSocketCompletionResult)).
  3. In the XAsyncOp::GetResult operation, fill the WebSocketCompletionResult buffer. Set websocket to the websocket parameter, errorCode to the connection result, and platformErrorCode to a platform-specific code for diagnostics.
While the WebSocket is connected, deliver incoming messages and the close event through the functions returned by HCWebSocketGetEventFunctions. This callback type isn’t declared when HC_NOWEBSOCKETS is defined.

Requirements

Header: httpProvider.h Library: libHttpClient.lib Supported platforms: Windows, XBOX One family consoles and XBOX Series consoles

See also

httpProvider
HCSetWebSocketFunctions
HCGetWebSocketFunctions
Last modified on October 30, 2026