> ## 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.

# HCWebSocketSendBinaryMessageFunction

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

# HCWebSocketSendBinaryMessageFunction

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

## Syntax

```cpp theme={null}
HRESULT CALLBACK HCWebSocketSendBinaryMessageFunction(
         HCWebsocketHandle websocket,
         const uint8_t* payloadBytes,
         uint32_t payloadSize,
         XAsyncBlock* asyncBlock,
         void* context
)
```

### Parameters

*websocket*   \_In\_\
Type: HCWebsocketHandle

The handle of the connected WebSocket.

*payloadBytes*   \_In\_reads\_bytes\_(payloadSize)\
Type: const uint8\_t\*

The binary data to send.

*payloadSize*   \_In\_\
Type: uint32\_t

The size of `payloadBytes`, in bytes.

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

The async block that the title passed to HCWebSocketSendBinaryMessageAsync.

*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 HCWebSocketSendBinaryMessageAsync. 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, HCWebSocketSendBinaryMessageAsync 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. Binary sends use the same identity as text sends. 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)
- [HCWebSocketSendBinaryMessageAsync](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketsendbinarymessageasync.md)
- [HCGetWebSocketSendMessageResult](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcgetwebsocketsendmessageresult.md)
