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

# XGameStreamingGetClientIPAddress

> XGameStreamingGetClientIPAddress

# XGameStreamingGetClientIPAddress

<Info>
  **已淘汰。** 此 API 自 2604 GDK 版本起已淘汰，並將在未來的 GDK 版本中移除。在目前的 XBOX Cloud Gaming 串流堆疊上，此 API 無法運作，且在成功時會傳回 `E_GAMESTREAMING_NO_DATA`。

  如果您的遊戲需要判斷是否在 XBOX Game Streaming 伺服器上執行，或需要使用者的大約地理位置，請改用 [XSTS 權杖宣告](/zh-TW/services/xbox-services/fundamentals/s2s-auth-calls/service-authentication/security-tokens/live-token-claims)。
</Info>

此 API 會傳回透過 XBOX 遊戲串流服務串流內容之終端使用者用戶端裝置的 IP 位址。只有在遵守 Microsoft 標準隱私權指導方針 (關於告知終端使用者資訊收集) 時，才應使用此 API 和相關資訊。如果您對此 API 的合規使用方式有任何疑問或疑慮，請聯絡您的 Microsoft 代表。

## 語法

```cpp theme={null}
HRESULT XGameStreamingGetClientIPAddress(  
         XGameStreamingClientId client,  
         size_t ipAddressSize,  
         char* ipAddress  
)  
```

### 參數

*client*   \_In\_\
類型：XGameStreamingClientId

正在查詢的串流用戶端。

*ipAddressSize*   \_In\_\
類型：size\_t

所提供之 `ipAddress` 緩衝區的大小上限。此值通常應直接使用 **ClientIPAddressMaxBytes**。

*ipAddress*   \_Out\_writes\_z\_(ipAddressSize)\
類型：char\*

將填入指定用戶端之 IP 位址的緩衝區。

### 傳回值

類型：HRESULT

如果成功，則傳回 **S\_OK**；否則傳回錯誤碼。

#### 可能的錯誤

| 錯誤碼 | 錯誤值 | 錯誤原因 |
| - | - | - |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400 | XGameStreaming 執行階段尚未初始化。呼叫其他 API 之前，請先呼叫 [XGameStreamingInitialize](/zh-TW/reference/system/xgamestreaming/functions/xgamestreaminginitialize)。 |
| E\_GAMESTREAMING\_CLIENT\_NOT\_CONNECTED | 0x89245401 | 指定的用戶端未連線。 |
| E\_GAMESTREAMING\_NO\_DATA | 0x89245402 | 要求的資料無法使用。資料稍後可能會可供使用。 |
| E\_NOT\_SUFFICIENT\_BUFFER | 0x7A | *ipAddress* 不夠大，無法容納 IP 位址和 Null 結束字元。 |

如需錯誤碼清單，請參閱[錯誤碼](/zh-TW/reference/errorcodes)。

## 備註

`ipAddress` 可以是 IPv4 位址 (1.2.3.4) 或 IPv6 位址 (1:2:3:4:5:6:7:8)。如有需要，可以使用 [ParseNetworkString](https://learn.microsoft.com/windows/win32/api/iphlpapi/nf-iphlpapi-parsenetworkstring) 來剖析字串。

傳回的 IP 位址是 XBOX 從串流用戶端收到的位址。如果串流用戶端使用 VPN 或位於 NAT 後方，則使用 IP 位址進行地理位置定位可能會發生問題。

<Note>
  在開發或遠端遊玩案例中，如果串流用戶端與 XBOX 位於同一個私人網路上，可能會傳回私人 IP 位址。
</Note>

## 範例

```C++ theme={null}
void GameStreamingClientManager::GetClientIPAddress(XGameStreamingClientId client)
{
    // Create the output buffer for the IP address
    char ipAddress[ClientIPAddressMaxBytes]; 

    // Get the IP address of the client 
    HRESULT hr = XGameStreamingGetClientIPAddress(client, ClientIPAddressMaxBytes, ipAddress); 

    if (SUCCEEDED(hr)) 
    { 
        // Game logic to use IP address
    } 
    else if (hr == E_GAMESTREAMING_CLIENT_NO_DATA) 
    { 
        // Game logic handles no data on client case 
    } 
    else 
    { 
        // In case of error just log and proceed as if there was no data 
        LogFormat(L"XGameStreamingGetClientIPAddress failed %x", hr); 
    } 
}
```

## 需求

**標頭：** xgamestreaming.h\
**程式庫：** xgameruntime.lib\
**支援的平台：** Windows、XBOX One 系列主機和 XBOX Series 主機

## 另請參閱

[XGameStreaming](/zh-TW/reference/system/xgamestreaming/xgamestreaming_members)


## Related topics

- [XGameStreamingGetClientIPAddress](/reference/system/xgamestreaming/functions/xgamestreaminggetclientipaddress.md)
- [XGameStreamingClientProperty](/reference/system/xgamestreaming/enums/xgamestreamingclientproperty.md)
- [Optimizing your game for XBOX Game Streaming](/build/core-features/common/game-streaming/game-streaming-optimizing-your-game.md)
- [XGameStreaming](/reference/system/xgamestreaming/xgamestreaming_members.md)
- [XBOX Game Streaming을 위한 게임 최적화](/ko/build/core-features/common/game-streaming/game-streaming-optimizing-your-game.md)
