> ## Documentation Index
> Fetch the complete documentation index at: https://docs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HCWebSocketSendMessageFunction

> Callback that sends a text WebSocket message when you replace the libHttpClient WebSocket implementation.

# HCWebSocketSendMessageFunction

Sends a text message on a WebSocket when you replace the libHttpClient WebSocket implementation. libHttpClient calls this callback when the title calls [HCWebSocketSendMessageAsync](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketsendmessageasync.md).

## Syntax

```cpp theme={null}
HRESULT CALLBACK HCWebSocketSendMessageFunction(
         HCWebsocketHandle websocket,
         const char* message,
         XAsyncBlock* asyncBlock,
         void* context
)
```

### Parameters

*websocket*   \_In\_\
Type: HCWebsocketHandle

The handle of the connected WebSocket.

*message*   \_In\_z\_\
Type: const char\*

The UTF-8 encoded text message to send.

*asyncBlock*   \_Inout\_\
Type: XAsyncBlock\*

The async block that the title passed to HCWebSocketSendMessageAsync.

*context*   \_In\_opt\_\
Type: void\*

The `context` value that you passed to [HCSetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcsetwebsocketfunctions.md).

### Return value

Type: HRESULT

libHttpClient returns this value to the caller of HCWebSocketSendMessageAsync. Return `S_OK` if the send operation started.

## Remarks

Register this callback, together with the other three WebSocket callbacks, by calling [HCSetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcsetwebsocketfunctions.md) before [HCInitialize](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcinitialize.md). HCSetWebSocketFunctions requires all four callbacks; it returns `E_INVALIDARG` if any of them is `nullptr`.

libHttpClient calls this callback only while the WebSocket is connected. Otherwise, HCWebSocketSendMessageAsync returns `E_UNEXPECTED` without calling the callback.

The title gets the result by calling [HCGetWebSocketSendMessageResult](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcgetwebsocketsendmessageresult.md), which calls `XAsyncGetResult` with `HCWebSocketSendMessageAsync` as the identity and a [WebSocketCompletionResult](https://docs.xbox.com/reference/live/httpclient/httpclient/structs/websocketcompletionresult.md) buffer. Your implementation must therefore begin the operation on `asyncBlock` by calling `XAsyncBegin` with `HCWebSocketSendMessageAsync` as the identity, complete it with `XAsyncComplete(asyncBlock, hr, sizeof(WebSocketCompletionResult))`, and fill the result in the `XAsyncOp::GetResult` operation.

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](https://docs.xbox.com/reference/live/httpclient/httpprovider/httpprovider_members.md)\
[HCSetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcsetwebsocketfunctions.md)\
[HCGetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcgetwebsocketfunctions.md)


## Related topics

- [HCGetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcgetwebsocketfunctions.md)
- [HCSetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcsetwebsocketfunctions.md)
- [httpProvider (contents)](https://docs.xbox.com/reference/live/httpclient/httpprovider/httpprovider_members.md)
- [HCWebSocketSendBinaryMessageFunction](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcwebsocketsendbinarymessagefunction.md)
- [HCWebSocketSendMessageAsync](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketsendmessageasync.md)
