当前位置:网站首页>Utilisation de la classe Ping d'Unity
Utilisation de la classe Ping d'Unity
2022-06-25 22:58:00 【Smart Zy.】
1.Objectif
1.1 Préparez - vous.pingRéseau,Voir sipingOK.,pingLe lien réseau est normal
2.RÉFÉRENCES
2.1
Unity De PingAnalyse des classes&Essayez d'utiliser_Le blog de Chen yanbing-CSDNBlogs
3.Attention!
3.1 Ça ne marche pas très bien,
- C'est clair.pingOK.,Mais il montrepingÇa ne marche pas.
- Il n'y a pas de variables à l'intérieur Est - ce quepingÇa marche.,
- ping_zhuJi.time=-1 ms ,En fait, l'ordinateur peutpingOK.,

Les codes sont les suivants:
- ping_zhuJi.timePrincipalement avec ceci et0Comparer les jugements pour déterminer si les liens sont
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 【Function:pingRéseau】【Time:2022 06 20】【Author:XZY】
/// </summary>
public class PingNet : MonoBehaviour
{
/// <summary>L'hôteip,Le but estping Ça marche? </summary>
[HideInInspector]
//public string ip_zhuJi = "192.168.1.111";
public string ip_zhuJi = "";
/// <summary>PingObjet:L'hôte</summary>
Ping ping_zhuJi=null;
/// <summary>PingObjet:Background</summary>
Ping ping_server;
/// <summary>Co - Process: Vérifiez si vous n'avez pas pingOK., Si c'est un représentant pingÇa ne marche pas.</summary>
private Coroutine coroutine_isPingSuccess=null;
/// <summary>pingUne fois</summary>
private float waitForSeconds_IE_isPingSuccess = 5;
/// <summary>pingNombre d'échecs,Avec le co - programmewaitForSeconds_IE_isPingSuccessC'est important</summary>
private int numPingFail = 0;
/// <summary>ping Combien de fois l'échec est un échec </summary>
private int totalPingFail = 3;
public static PingNet instance = null;
//public int NumPingFail { get => numPingFail; set => numPingFail = value; }
private void Awake()
{
if (instance == null)
{
instance = this;
}
}
private void Start()
{
//coroutine_isPingSuccess = StartCoroutine(IE_isPingSuccess());
//StartCoroutine(IE_GetIp_zhuJi());
//StartCoroutine(IE_StartPing());
}
//IEnumerator IE_GetIp_zhuJi()
//{
// yield return new WaitForSeconds(5);
// string _ip = SmartPlayerAndroidMono.Instance.ip_zhuJi;
// Debug.Log("PingNetAdresse: Obtenir l'adresse complète de l'hôte : " + _ip);
// string[] str_add = _ip.Split(':');
// for (int i = 0; i < str_add.Length; i++)
// {
// Debug.Log("PingNetAdresse:Obtenir l'hôteip:No " + i + "Champs:" + str_add[i]);
// }
// string str_add2 = str_add[1].Trim('/');
// Debug.Log("PingNetAdresse:Obtenir l'hôteip: " + str_add2);
//}
//IEnumerator IE_StartPing()
//{
// yield return new WaitForSeconds(6);
// string _ip = ip_zhuJi;
// if (_ip == "")
// {
// Debug.Log("PingNet:Adresse:L'hôteipVide,Veuillez vérifier.");
// yield return null;
// }
// else
// {
// ip_zhuJi = _ip;
// }
// if (ping_zhuJi != null)
// {
// ping_zhuJi.DestroyPing();
// ping_zhuJi = null;
// }
// ping_zhuJi = new Ping(ip_zhuJi);
// if (coroutine_isPingSuccess != null)
// {
// StopCoroutine(IE_isPingSuccess());
// coroutine_isPingSuccess = null;
// }
// coroutine_isPingSuccess = StartCoroutine(IE_isPingSuccess());
//}
/// <summary>
/// 【Function:Obtenir l'hôteip】【Time:2022 06 21】【Author:XZY】
/// </summary>
string GetIp_zhuJi()
{
string _ip = SmartPlayerAndroidMono.Instance.ip_zhuJi_all;
Debug.Log("PingNetAdresse: Obtenir l'adresse complète de l'hôte : " + _ip);
string[] str_add = _ip.Split(':');
for (int i = 0; i < str_add.Length; i++)
{
Debug.Log("PingNetAdresse:Obtenir l'hôteip:No " + i + "Champs:" + str_add[i]);
}
string str_add2 = str_add[1].Trim('/');
Debug.Log("PingNetAdresse:Obtenir l'hôteip: " + str_add2);
return str_add2;
}
/// <summary>
/// 【Function:C'est parti.ping】【Time:2022 06 20】【Author:XZY】
/// </summary>
public void StartPing()
{
string _ip = GetIp_zhuJi();
if (_ip == "")
{
Debug.Log("PingNet:Adresse:L'hôteipVide,Veuillez vérifier.");
return;
}
else
{
ip_zhuJi = _ip;
}
if (ping_zhuJi != null)
{
ping_zhuJi.DestroyPing();
ping_zhuJi = null;
}
ping_zhuJi = new Ping(ip_zhuJi);
if (coroutine_isPingSuccess != null)
{
StopCoroutine(IE_isPingSuccess());
coroutine_isPingSuccess = null;
}
coroutine_isPingSuccess = StartCoroutine(IE_isPingSuccess());
}
/ <summary>
/ 【Function:Envoyerping】【Time:2022 06 20】【Author:XZY】
/ </summary>
//void SendPing()
//{
// ping_zhuJi = new Ping(ip_zhuJi);
//}
/// <summary>
/// 【Function:Co - Process:Est - ce quepingSuccès】【Time:2022 06 20】【Author:XZY】
/// </summary>
/// <returns></returns>
IEnumerator IE_isPingSuccess()
{
while (true)
{
//Debug.Log("Adresse:IE_isPingSuccess:");
yield return new WaitForSeconds(waitForSeconds_IE_isPingSuccess);
Debug.Log("PingNetAdresse:null != ping_zhuJi:" + (null != ping_zhuJi));
Debug.Log("PingNetAdresse:ping_zhuJi.isDone:" + ping_zhuJi.isDone);
//Uniquement pardelayTimeDe<0Déterminer sipingOK.,Si<0C'est - à - dire non.pingOK.;Au contrairepingOK.
if (null != ping_zhuJi && ping_zhuJi.isDone)
{
float delayTime = ping_zhuJi.time;
if (delayTime <= 0)
{
numPingFail++;
Debug.Log("PingNetAdresse:ip_zhuJi:" + ip_zhuJi + ":pingNombre d'échecs:" + numPingFail);
Debug.Log("PingNetAdresse:Ping:Pas depuis longtemps.pingOK.");
//Déconnecter le lienUI Afficher
ConnectTipPanel.instance.AddConnectFail();
}
else
{
Debug.Log("PingNetAdresse:ping_zhuJi:" + ip_zhuJi + ":" + delayTime.ToString() + " ms");
numPingFail = 0;
Debug.Log("PingNetAdresse:ip_zhuJi:" + ip_zhuJi + ":pingSuccès");
//Déconnecter le lienUI Cacher
ConnectTipPanel.instance.ConnectSuccess();
}
}
ping_zhuJi.DestroyPing();
ping_zhuJi = null;
ping_zhuJi = new Ping(ip_zhuJi);
}
}
}
边栏推荐
- 在线CRUDhasone关联查询报错Unabletouseinternalvariable:List
- 聊聊Adapter模式
- Raspberry PI (bullseye) replacement method of Alibaba cloud source
- ES6 --- 数值扩展、对象拓展
- Unity technical manual - particle emission and life cycle velocity sub module
- QT learning setting executable exe attribute (solving the problem of Chinese attribute garbled)
- What is 5g? What can 5g do? What will 5g bring in the future?
- Thinking while walking
- 你好,请问老师,在支付宝基金开户真的安全吗?
- Dialog+: Audio dialogue enhancement technology based on deep learning
猜你喜欢

2022-2028 global cloud based remote browser isolation industry research and trend analysis report
![[intensive lecture] 2022 PHP intermediate and advanced interview questions (II)](/img/50/c9572beaa035d5e6e78a57fcd1302c.jpg)
[intensive lecture] 2022 PHP intermediate and advanced interview questions (II)

Trillions of hot money smashed into the space economy. Is it really a good business?

Obsidian基础教程

2022-2028 global co extrusion production line industry research and trend analysis report

万亿热钱砸向太空经济,真的是一门好生意?

2022-2028 global carbon fiber unidirectional tape industry research and trend analysis report

Use apiccloud AVM multi terminal component to quickly realize the search function in the app

2022-2028 global SiC igniter industry research and trend analysis report

2022-2028 global open source cloud storage industry research and trend analysis report
随机推荐
2022-2028 global iridium electrode industry research and trend analysis report
oracle -- 表操作
Research and Analysis on the current situation of Chinese acne drug market and forecast report on its development prospect (2022)
c语言与数据库的创建使用
ORACLE - 数据查询
[intensive lecture] 2022 PHP intermediate and advanced interview questions (II)
1281_FreeRTOS_vTaskDelayUntil实现分析
2022爱分析· IT运维厂商全景报告
Huawei cloud SMS has tested that many mobile phones prompt frequent sending
C language and the creation and use of database
记|一次exists关键字的学习记录
Research and Analysis on the current situation of China's magnetic detector Market and forecast report on its development prospect (2022)
Initialization process of gstlibav
Simple and easy-to-use cache library gcache
Mysql database index
China bed and mattress market status research analysis and development prospect forecast report (2022)
Relinearization in homomorphic encryption (ckks)
Three layer architecture + routing experiment
在线CRUDhasone关联查询报错Unabletouseinternalvariable:List
聊聊Adapter模式