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

# XGameStreamingRegisterConnectionStateChanged

> XGameStreamingRegisterConnectionStateChanged

# XGameStreamingRegisterConnectionStateChanged

스트리밍 클라이언트 장치의 연결 상태가 변경될 때 호출될 콜백을 등록합니다. 등록 시, 이미 연결되어 있는 모든 스트리밍 클라이언트 장치에 대해 콜백이 호출됩니다.

## 구문

```cpp theme={null}
HRESULT XGameStreamingRegisterConnectionStateChanged(  
         XTaskQueueHandle queue,  
         void* context,  
         XGameStreamingConnectionStateChangedCallback* callback,  
         XTaskQueueRegistrationToken* token  
)  
```

### 매개 변수

*queue*   \_In\_opt\_\
형식: XTaskQueueHandle

변경 콜백을 배치할 비동기 큐에 대한 핸들입니다.

*context*   \_In\_opt\_\
형식: void\*

콜백 함수에 전달되는 컨텍스트에 대한 선택적 포인터입니다.

*callback*   \_In\_\
형식: XGameStreamingConnectionStateChangedCallback\*

스트리밍 클라이언트 장치의 연결 상태가 변경될 때 호출될 콜백 함수입니다.

*token*   \_Out\_\
형식: XTaskQueueRegistrationToken\*

이벤트 등록을 해제하는 데 사용할 수 있는 등록 토큰에 대한 포인터입니다.

### 반환 값

형식: HRESULT

성공하면 **S\_OK**를 반환하고, 그렇지 않으면 오류 코드를 반환합니다.

#### 잠재적 오류

| 오류 코드                              | 오류 값       | 오류 원인                                                                                                                                                    |
| ---------------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400 | XGameStreaming 런타임이 초기화되지 않았습니다. 다른 API를 호출하기 전에 [XGameStreamingInitialize](/reference/system/xgamestreaming/functions/xgamestreaminginitialize)를 호출하세요. |

오류 코드 목록은 [오류 코드](/reference/errorcodes)를 참조하세요.

## 설명

<Note>이 함수는 시간에 민감한 스레드에서 호출하기에 안전하지 않습니다. 자세한 내용은 [시간에 민감한 스레드](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)를 참조하세요.</Note>

이 API는 게임이 스트리밍 클라이언트 장치별로 사용자 지정을 수행하고, 연결된 장치가 있는지 여부에 따라 환경을 최적화할 수 있도록 상태를 유지하는 권장 방법입니다.

<Note>등록 시, 현재 연결된 모든 스트리밍 클라이언트 장치에 대해 콜백이 호출됩니다.</Note>

## 예제

```cpp theme={null}
    // Called during game startup to hook into any game streaming start/stop events
    void SetupStreamAware()
    {
        // Register a callback for client connections and disconnections. Note that the connection callback
        // will fire for any already connected clients, so do all of our per-client setup in that callback.      
        XGameStreamingConnectionStateChangedRegistrationToken stateChangeToken = {0};
        XGameStreamingRegisterConnectionStateChanged(
            m_taskQueue, this, ConnectionStateChangedCallback, &stateChangeToken);
    }

    static void ConnectionStateChangedCallback(void* context, XGameStreamingClientId client, XGameStreamingConnectionState state)
    {
        static_cast<Game*>(context)->OnConnectionStateChanged(client, state);
    }

    void OnConnectionStateChanged(XGameStreamingClientId client, XGameStreamingConnectionState state)
    {
        switch (state)
        {
        case XGameStreamingConnectionState::Connected: 
            OnClientConnected(client); 
            break;
        case XGameStreamingConnectionState::Disconnected: 
            OnClientDisconnected(client); 
            break;
        default: 
            break;
        }
    }


    void OnClientConnected(XGameStreamingClientId client)
    {
        // Update list of connected clients
        m_streamingClients.push_back(client);

        // Do per-client initialization
        // ...
    }

    void OnClientDisconnected(XGameStreamingClientId client)
    {
        // Release our reference on the client that is no longer streaming the game
        std::remove(m_streamingClients.begin(), m_streamingClients.end(), client);

        // Do per-client cleanup
        // ...
    }



```

## 요구 사항

**헤더:** xgamestreaming.h

**라이브러리:** xgameruntime.lib

**지원 플랫폼:** Windows, XBOX One 계열 콘솔 및 XBOX Series 콘솔

## 개념 문서

* [클라우드 인식 API 호출](/build/core-features/common/game-streaming/game-streaming-am-i-streaming)
* [시간에 민감한 스레드](https://learn.microsoft.com/gaming/gdk/docs/gdk-dev/console-dev/overviews/threads/time-sensitive-threads)

## 함께 보기

[XGameStreamingConnectionState](/reference/system/xgamestreaming/enums/xgamestreamingconnectionstate)\
[XGameStreamingConnectionStateChangedCallback](/reference/system/xgamestreaming/functions/xgamestreamingconnectionstatechangedcallback)\
[XGameStreamingUnregisterConnectionStateChanged](/reference/system/xgamestreaming/functions/xgamestreamingunregisterconnectionstatechanged)\
[XGameStreaming](/reference/system/xgamestreaming/xgamestreaming_members)


## Related topics

- [XGameStreamingUnregisterConnectionStateChanged](/ko/reference/system/xgamestreaming/functions/xgamestreamingunregisterconnectionstatechanged.md)
- [XGameStreamingConnectionStateChangedCallback](/ko/reference/system/xgamestreaming/functions/xgamestreamingconnectionstatechangedcallback.md)
- [XGameStreamingConnectionState](/ko/reference/system/xgamestreaming/enums/xgamestreamingconnectionstate.md)
- [XGameStreamingIsStreaming](/ko/reference/system/xgamestreaming/functions/xgamestreamingisstreaming.md)
- [XGameStreamingGetConnectionState](/ko/reference/system/xgamestreaming/functions/xgamestreaminggetconnectionstate.md)
