Platform | Support Status |
Windows (Standalone) | Supported |
Android | Supported |
iOS | Supported |
Unity Editor | Supported (using Windows DLL) |
Assets/└── Plugins/└── Unity_CLS/├── Unity_CLS.cs # C# unified interface layer├── Android/│ └── libs/│ ├── all-dependencies-1.0.0-shaded.jar # java dependencies required for Android│ ├── network-diagnosis-release.aar # network probing dependency│ ├── producer-release.aar # log reporting dependency│ └── unity-release.aar # unity interaction dependency├── Windows/│ └── cls_network_detect.dll # windows network probing + log reporting dynamic library└── iOS/├── UnityApi.h # bridging code for interacting with ios├── UnityApi.m├── TencentCloudLogProducer.framework # cls ios sdk package├── FMDB.framework # dependency required by the cls ios sdk├── Protobuf.framework└── Reachability.framework
<uses-permission android:name="android.permission.INTERNET" /><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application> Tag:<application android:usesCleartextTraffic="true">
using System.Collections.Generic;using UnityEngine;using TencentCloudCLS;public class NetworkDiagnosisDemo : MonoBehaviour{void Start(){// 1. Initialize SDK.Credential credential = new Credential();credential.endpoint = "ap-guangzhou.cls.tencentcs.com";credential.secretId = "Your SecretId";credential.secretKey = "Your SecretKey";credential.geoToken = "Your GeoToken";Unity_CLS.Initialize(credential);// 2. Set user-defined extended fields (optional)Dictionary<string, string> userCustomField = new Dictionary<string, string>();userCustomField.Add("app_version", "1.0.0");userCustomField.Add("user_id", "12345");Unity_CLS.SetUserCustom(userCustomField);// 3. Perform TCP Ping detectionTcpPingRequest tcpRequest = new TcpPingRequest();tcpRequest.target = "www.baidu.com";tcpRequest.port = 80;tcpRequest.callback = (response) =>{Debug.Log("TCP Ping Result: " + response);};Unity_CLS.TcpPing(tcpRequest);}}
Unity_CLS.Initialize(Credential credential)
Field | Type | Required | Description |
endpoint | string | Yes | CLS service endpoint, such as "ap-guangzhou.cls.tencentcs.com" |
secretId | string | Yes | |
secretKey | string | Yes | |
topicId | string | No | CLS log topic ID (optional when geoToken is used) |
geoToken | string | No |
Credential credential = new Credential();credential.endpoint = "ap-guangzhou.cls.tencentcs.com";credential.secretId = "Your SecretId";credential.secretKey = "Your SecretKey";credential.geoToken = "Your GeoToken";Unity_CLS.Initialize(credential);
Unity_CLS.SetUserCustom(Dictionary<string, string> userCustomField)
Dictionary<string, string> userCustomField = new Dictionary<string, string>();userCustomField.Add("app_version", "1.0.0");userCustomField.Add("user_id", "12345");userCustomField.Add("channel", "official");Unity_CLS.SetUserCustom(userCustomField);
Unity_CLS.TcpPing(TcpPingRequest request)
Field | Type | Default Value | Platform Support | Description |
target | string | "" | Entire platform | Target hostname or IP address |
port | int | -1 | Entire platform | Target port number |
count | int | 1 | Entire platform | Number of probes |
timeout | int | 1000 | Entire platform | Timeout (ms) |
size | int | 0 | Windows/Android | Packet size to send (in bytes), where 0 means no data is sent |
payload | string | null | Windows/Android | Test data content to be sent to the target port |
interval | int | 300 | Windows | Probe interval (ms) |
enableVerification | int | 1 | Windows | Whether to enable connection verification 1: Enabled 0: Disabled |
prefer | int | 0 | Windows/iOS | IP version preference 0: IPv4 Preferred 1: IPv6 Preferred 2:IPv4 only 3:IPv6 only |
netId | int | 0 | Windows | Network adapter ID |
traceId | string | null | Entire platform | Trace ID (can be null, auto-generated) |
src | string | null | Windows | Source identifier |
multiplePortsDetect | bool | true | Android | Whether to perform multi-port detection |
enableMultiplePortsDetect | bool | false | iOS | Whether to enable multi-port detection |
detectCustomField | Dictionary | Empty dictionary | Entire platform | Extended field for detection |
callback | callback_response | null | Entire platform | Result callback function |
TcpPingRequest request = new TcpPingRequest();request.target = "www.baidu.com";request.port = 80;request.count = 3;request.timeout = 2000;request.detectCustomField = new Dictionary<string, string>(){{ "scene", "login_page" }};request.callback = (response) =>{Debug.Log("TCP Ping Result: " + response);};Unity_CLS.TcpPing(request);
Unity_CLS.Ping(PingRequest request)
Field | Type | Default Value | Platform Support | Description |
target | string | "" | Entire platform | Target hostname or IP address |
count | int | 1 | Entire platform | Number of probes |
timeout | int | 1000 | Entire platform | Timeout (ms) |
packetSize | int | 100 | Windows/Android | Packet size (in bytes, excluding the ICMP header) |
interval | int | 300 | Windows/iOS | Probe interval (ms) |
ttl | int | 64 | Windows | TTL value |
prefer | int | 0 | Windows/iOS | IP version preference |
netId | int | 0 | Windows | Network adapter ID |
traceId | string | null | Entire platform | Trace ID |
src | string | null | Windows | Source identifier |
multiplePortsDetect | bool | true | Android | Whether to perform multi-port detection |
enableMultiplePortsDetect | bool | false | iOS | Whether to enable multi-port detection |
detectCustomField | Dictionary | Empty dictionary | Entire platform | Extended field for detection |
callback | callback_response | null | Entire platform | Result callback function |
PingRequest request = new PingRequest();request.target = "www.baidu.com";request.count = 5;request.timeout = 3000;request.callback = (response) =>{Debug.Log("Ping Result: " + response);};Unity_CLS.Ping(request);
Unity_CLS.Http(HttpRequest request)
Field | Type | Default Value | Platform Support | Description |
url | string | "" | Entire platform | Target URL (must include the protocol header, such as http:// or https://). |
count | int | 1 | Android/iOS | Number of probes |
timeout | int | 1000 | Entire platform | Timeout (ms) |
interval | int | 300 | Windows | Probe interval (ms) |
ip | string | null | Android | Specified IP address (uses DNS resolution when null). |
downloadBytesLimit | int | 0 | Windows | Download byte limit, where 0 means unlimited. |
downloadHeaderOnly | int | 0 | Windows | Whether to download headers only 1: Headers Only 0: Full Content |
verifySslCert | int | 0 | Windows/iOS | Whether to verify SSL Certificates 1: Verify 0: Do Not Verify |
size | int | 0 | Android | Packet size to send |
prefer | int | 0 | Windows/iOS | IP version preference |
netId | int | 0 | Windows | Network adapter ID |
traceId | string | null | Entire platform | Trace ID |
src | string | null | Windows | Source identifier |
multiplePortsDetect | bool | true | Android | Whether to perform multi-port detection |
enableMultiplePortsDetect | bool | false | iOS | Whether to enable multi-port detection |
detectCustomField | Dictionary | Empty dictionary | Entire platform | Extended field for detection |
callback | callback_response | null | Entire platform | Result callback function |
HttpRequest request = new HttpRequest();request.url = "https://www.baidu.com";request.timeout = 5000;request.callback = (response) =>{Debug.Log("HTTP Probe Result: " + response);};Unity_CLS.Http(request);
Unity_CLS.Dns(DnsRequest request)
Field | Type | Default Value | Platform Support | Description |
domain | string | "" | Entire platform | Target domain name. |
type | string | null | Windows/Android | DNS query type (such as "A" and "AAAA", defaults to A when null) |
servers | string | null | Entire platform | DNS server list (comma-separated, such as "8.8.8.8,8.8.4.4", uses system default when null) |
count | int | 1 | Android | Number of probes |
timeout | int | 1000 | Entire platform | Timeout (ms) |
size | int | 0 | Android | Packet size to send |
prefer | int | 0 | Windows/iOS | IP version preference |
traceId | string | null | Entire platform | Trace ID |
src | string | null | Windows | Source identifier |
multiplePortsDetect | bool | true | Android | Whether to perform multi-port detection |
enableMultiplePortsDetect | bool | false | iOS | Whether to enable multi-port detection |
detectCustomField | Dictionary | Empty dictionary | Entire platform | Extended field for detection |
callback | callback_response | null | Entire platform | Result callback function |
DnsRequest request = new DnsRequest();request.domain = "www.baidu.com";request.servers = "8.8.8.8";request.callback = (response) =>{Debug.Log("DNS Resolution Result: " + response);};Unity_CLS.Dns(request);
Unity_CLS.Mtr(MtrRequest request)
Field | Type | Default Value | Platform Support | Description |
target | string | "" | Entire platform | Target hostname or IP address |
maxTtl | int | 30 | Entire platform | Maximum TTL value (maximum number of hops, 1 - 255) |
times | int | 10 | Entire platform | Number of probes per hop |
timeout | int | 1000 | Entire platform | Timeout (ms) |
interval | int | 300 | Windows | Detection interval (ms) |
protocol | string | "icmp" | Windows/Android | Protocol type ("icmp", "tcp", "udp") |
destPort | int | 0 | Windows | Target port (used for TCP/UDP protocols) |
maxPaths | int | 1 | Windows/Android | Maximum number of paths (1 - 10) |
size | int | 0 | Android | Packet size to send |
prefer | int | 0 | Windows/iOS | IP version preference |
netId | int | 0 | Windows | Network adapter ID |
traceId | string | null | Entire platform | Trace ID |
src | string | null | Windows | Source identifier |
multiplePortsDetect | bool | true | Android | Whether to perform multi-port detection |
enableMultiplePortsDetect | bool | false | iOS | Whether to enable multi-port detection |
detectCustomField | Dictionary | Empty dictionary | Entire platform | Extended field for detection |
callback | callback_response | null | Entire platform | Result callback function |
MtrRequest request = new MtrRequest();request.target = "www.baidu.com";request.maxTtl = 30;request.times = 5;request.protocol = "icmp";request.callback = (response) =>{Debug.Log("MTR Result: " + response);};Unity_CLS.Mtr(request);
using System;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;using TencentCloudCLS;public class NetworkDiagnosisManager : MonoBehaviour{void Start(){Debug.Log("[NetworkDiagnosis] Starting initialization...");}/// <summary>/// Initialize the SDK (must be called before any probing operations)/// </summary>public void Init(){Credential credential = new Credential();credential.endpoint = "ap-guangzhou.cls.tencentcs.com";credential.secretId = "Your SecretId";credential.secretKey = "Your SecretKey";credential.geoToken = "Your GeoToken";Unity_CLS.Initialize(credential);// Set user-defined extended fieldsDictionary<string, string> userCustomField = new Dictionary<string, string>();userCustomField.Add("app_version", "1.0.0");userCustomField.Add("scene", "main_menu");Unity_CLS.SetUserCustom(userCustomField);Debug.Log("[NetworkDiagnosis] Initialization completed.");}/// <summary>/// Perform TCP Ping detection/// </summary>public void DoTcpPing(){TcpPingRequest request = new TcpPingRequest();request.target = "www.baidu.com";request.port = 80;request.count = 3;request.detectCustomField = new Dictionary<string, string>(){{ "test_type", "tcp_ping" }};request.callback = (response) =>{Debug.Log("[TCP Ping] Result: " + response);};Unity_CLS.TcpPing(request);}/// <summary>/// Perform ICMP Ping detection/// </summary>public void DoPing(){PingRequest request = new PingRequest();request.target = "www.baidu.com";request.count = 5;request.detectCustomField = new Dictionary<string, string>(){{ "test_type", "icmp_ping" }};request.callback = (response) =>{Debug.Log("[Ping] Result: " + response);};Unity_CLS.Ping(request);}/// <summary>/// Perform HTTP detection/// </summary>public void DoHttp(){HttpRequest request = new HttpRequest();request.url = "http://www.baidu.com";request.timeout = 5000;request.detectCustomField = new Dictionary<string, string>(){{ "test_type", "http" }};request.callback = (response) =>{Debug.Log("[HTTP] Result: " + response);};Unity_CLS.Http(request);}/// <summary>/// Perform DNS resolution detection/// </summary>public void DoDns(){DnsRequest request = new DnsRequest();request.domain = "www.baidu.com";request.detectCustomField = new Dictionary<string, string>(){{ "test_type", "dns" }};request.callback = (response) =>{Debug.Log("[DNS] Result: " + response);};Unity_CLS.Dns(request);}/// <summary>/// Perform MTR route tracing/// </summary>public void DoMtr(){MtrRequest request = new MtrRequest();request.target = "www.baidu.com";request.maxTtl = 30;request.times = 3;request.detectCustomField = new Dictionary<string, string>(){{ "test_type", "mtr" }};request.callback = (response) =>{Debug.Log("[MTR] Result: " + response);};Unity_CLS.Mtr(request);}}
public delegate void callback_response(string response);
Dictionary<string, string> userCustomField = new Dictionary<string, string>();userCustomField.Add("user_id", "12345");userCustomField.Add("app_version", "2.0.0");Unity_CLS.SetUserCustom(userCustomField);
request.detectCustomField = new Dictionary<string, string>(){{ "scene", "game_loading" },{ "server_region", "ap-shanghai" }};
Parameter | Windows | Android | iOS |
interval (probe interval) | ✅ | ❌ | Partially supported |
prefer (IP version preference) | ✅ | ❌ | ✅ |
netId (network adapter ID) | ✅ | ❌ | ❌ |
src (source identifier) | ✅ | ❌ | ❌ |
multiplePortsDetect | ❌ | ✅ | ❌ |
enableMultiplePortsDetect | ❌ | ❌ | ✅ |
enableVerification(TCP) | ✅ | ❌ | ❌ |
payload(TCP) | ✅ | ✅ | ❌ |
protocol(MTR) | ✅ | ✅ | ✅ |
Platform | Implementation Method |
Windows / Editor | Call the C native library via DLL (cls_network_detect.dll) P/Invoke. |
Android | Call the Java-layer SDK (AAR package) via AndroidJavaClass. |
iOS | Call the Objective-C bridging layer (UnityApi.m → TencentCloudLogProducer.framework) via DllImport __Internal. |
Esta página foi útil?
Você também pode entrar em contato com a Equipe de vendas ou Enviar um tíquete em caso de ajuda.
comentários