当前位置:网站首页>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);
}
}
}
边栏推荐
- Research and Analysis on the current situation of Chinese acne drug market and forecast report on its development prospect (2022)
- 2022-2028 global transmission type photoelectric circuit breaker industry research and trend analysis report
- Data governance is easier said than done
- ADB common commands
- 你好,请问老师,在支付宝基金开户真的安全吗?
- 哪些PHP开源作品值得关注
- Relinearization in homomorphic encryption (ckks)
- How to use the find command
- 民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
- ES6-Const常量与数组解构
猜你喜欢

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

Nacos source code analysis 01 code structure

ES6 -- 形参设置初始值、拓展运算符、迭代器、生成函数

Facing the "industry, University and research" gap in AI talent training, how can shengteng AI enrich the black land of industrial talents?

作为一个程序员我们如何快乐的学习成长进步呢?(个人感悟和技术无关)

2022-2028 global industrial TFT LCD industry survey and trend analysis report

Openwrt (VIII) application layer development

How to design a complex business system? From the understanding of domain design, cloud native, micro service, and middle platform

Yyds dry goods inventory CEPH installation visual dashboard
Interview shock 23: talk about thread life cycle and transformation process?
随机推荐
MySQL数据库索引
Online crudhasone Association query reports an error unabletouseinternalvariable:list
Trillions of hot money smashed into the space economy. Is it really a good business?
oracle -- 表操作
2022-2028 global RBI platform industry research and trend analysis report
GStreamer initialization and plugin registry procedures
Flutter 网络请求封装之Dio(Cookie管理、添加拦截器、下载文件、异常处理、取消请求等)
NRM source switching tool
Unity技术手册 - 粒子基础主模块属性-上
Development trend of China's power carrier communication industry and Research Report on the 14th five year plan 2022 ~ 2028
关闭MongoDB一些服务需要注意的地方(以及开启的相关命令)
ES6-- 模板字符串、对象的简化写法、箭头函数
实战:typora里面如何快捷改变字体颜色(博客分享-完美)-2022.6.25(已解决)
zabbix_server配置文件详解
2022-2028 global DC linear variable differential transformer (LVDT) industry survey and trend analysis report
Touring band: a 5g based multi camera remote distributed video production experiment
ES6 --- 数值扩展、对象拓展
Dio encapsulé pour les requêtes réseau flutter (gestion des cookies, ajout d'intercepteurs, téléchargement de fichiers, gestion des exceptions, annulation des requêtes, etc.)
2022-2028 global proton exchange membrane hydrogen electrolyzer industry survey and trend analysis report
Analysis report on scale investigation and investment development suggestions of China's special equipment inspection and testing industry 2022-2028