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

# HCWebSocketDisconnectFunction

> Callback that closes a WebSocket when you replace the libHttpClient WebSocket implementation.

# HCWebSocketDisconnectFunction

Closes a WebSocket when you replace the libHttpClient WebSocket implementation. libHttpClient calls this callback when the title calls [HCWebSocketDisconnect](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketdisconnect.md) or [HCWebSocketDisconnectWithStatus](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketdisconnectwithstatus.md).

## Syntax

```cpp theme={null}
HRESULT CALLBACK HCWebSocketDisconnectFunction(
         HCWebsocketHandle websocket,
         HCWebSocketCloseStatus closeStatus,
         void* context
)
```

### Parameters

*websocket*   \_In\_\
Type: HCWebsocketHandle

The handle of the WebSocket to close.

*closeStatus*   \_In\_\
Type: HCWebSocketCloseStatus

The close status to send to the peer. HCWebSocketDisconnect passes `HCWebSocketCloseStatus::Normal`.

*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 HCWebSocketDisconnect or HCWebSocketDisconnectWithStatus.

## 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 invokes this callback synchronously; it has no async block. Start the close handshake and return. The close handshake itself doesn't need to finish before the callback returns.

When the connected WebSocket closes, report the closure by calling the close event function returned by [HCWebSocketGetEventFunctions](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketgeteventfunctions.md), passing the `websocket` handle and the context returned with that function. libHttpClient uses this notification to release the state that it keeps for the connection.

libHttpClient calls this callback only while the WebSocket is connected. If a disconnect is already in progress, HCWebSocketDisconnect returns `S_OK` without calling the callback again.

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

- [HCSetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcsetwebsocketfunctions.md)
- [HCGetWebSocketFunctions](https://docs.xbox.com/reference/live/httpclient/httpprovider/functions/hcgetwebsocketfunctions.md)
- [httpProvider (contents)](https://docs.xbox.com/reference/live/httpclient/httpprovider/httpprovider_members.md)
- [HCWebSocketDisconnect](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketdisconnect.md)
- [HCWebSocketDisconnectWithStatus](https://docs.xbox.com/reference/live/httpclient/httpclient/functions/hcwebsocketdisconnectwithstatus.md)
