当前位置:网站首页>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);
}
}
}
边栏推荐
- How to use the find command
- 华为云短信测了很多手机都提示发送频繁
- 2022-2028 global extrusion coating and lamination production line industry research and trend analysis report
- Some reflections on preparing for the Blue Bridge Cup
- Why can't the mobile phone be used and the computer be connected
- Glory launched the points mall to support the exchange of various glory products
- Use apiccloud AVM multi terminal component to quickly realize the search function in the app
- Reasons why MySQL cannot be connected externally after installing MySQL database on ECs and Solutions
- GStreamer initialization and plugin registry procedures
- ORACLE - 数据查询
猜你喜欢

OSPF - detailed explanation of GRE tunnel (including configuration command)

Tiger Dao VC products are officially launched, a powerful supplement to seektiger ecology

哪些PHP开源作品值得关注

Basic concepts of processor scheduling

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

2022-2028 global TFT LCD touch screen industry research and trend analysis report

如何用jmeter做接口测试
![[intensive lecture] 2022 PHP intermediate and advanced interview questions (II)](/img/50/c9572beaa035d5e6e78a57fcd1302c.jpg)
[intensive lecture] 2022 PHP intermediate and advanced interview questions (II)

2022爱分析· IT运维厂商全景报告

Trillions of hot money smashed into the space economy. Is it really a good business?
随机推荐
2022-2028 global web and browser isolation platform industry research and trend analysis report
ES6-- 模板字符串、对象的简化写法、箭头函数
如何用jmeter做接口测试
Reasons why MySQL cannot be connected externally after installing MySQL database on ECs and Solutions
Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028
2022-2028 global extrusion coating and lamination production line industry research and trend analysis report
Hotspot JVM "01" class loading, linking and initialization
再突破!阿里云进入Gartner云AI开发者服务挑战者象限
Talk about adapter mode
Yyds dry goods inventory JD 2, why is redis so fast?
2022年河南省第一届职业技能大赛网络安全项目试题
Privatization lightweight continuous integration deployment scheme -- 03 deployment of Web services (Part 2)
MySQL数据库常用函数和查询
2022-2028 global TFT LCD touch screen industry research and trend analysis report
ES7/ES9 -- 新特性与正则
Three layer architecture + routing experiment
ES6学习-- LET
oracle -- 表操作
Wpewebkit debugging MSE playback
Does jQuery cache any selectors- Does jQuery do any kind of caching of “selectors”?