using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;
using System.Net;
using System.Text;
using Shared.SimpleControl;
namespace Shared
{
public class API
{
public static long PingServerAddress (string serverAddress)
{
long mRoundtripTime = 2000;
try {
//serverAddress = "www.baidu.com";
Ping pingSender = new Ping ();
PingOptions options = new PingOptions ();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.Ttl = 150;
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
//string data = "a";
byte [] buffer = Encoding.ASCII.GetBytes (string.Empty);
PingReply reply = pingSender.Send (serverAddress, 2000, buffer, options);
if (reply.Status == IPStatus.Success) {
Console.WriteLine ("Address: {0}", reply.Address.ToString ());
Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
mRoundtripTime = reply.RoundtripTime;
}
} catch (Exception ex) {
System.Console.WriteLine ($"Ping catch:{ex.ToString()}");
}
return mRoundtripTime;
//Console.ReadKey ();
}
# region EmqMqtt 部分
//***************************EmqMqtt 部分********************************
public static string API_HangZhouHdlCloudApi = "https://global.hdlcontrol.com/HangZhouHdlCloudApi/EmqMqtt/";
///
/// 客户端确定选择Emq服务器(默认没有选择则使用中国Emq服务器)
/// Connection
///
public static string ConfirmSelectEmqRegion = API_HangZhouHdlCloudApi + "ConfirmSelectEmqRegion";
///
/// 客户端获取关联的所有成员帐号信息
/// Connection
///
public static string GetShareMemberInfoPagger = API_HangZhouHdlCloudApi + "GetShareMemberInfoPagger";
///
/// 客户端获取连接云端Mqtt信息
/// Connection
///
public static string GetConnMqttInfo = API_HangZhouHdlCloudApi + "GetConnMqttInfo";
///
/// 获取分享者Mqtt远程控制信息
/// Connection
///
public static string GetShareMemberConnMqttInfo = API_HangZhouHdlCloudApi + "ShareMemberConnMqttInfo";
///
/// 获取所有区Emq服务器信息列表
/// Connection
///
public static string GetAllRegionEmqServerList = API_HangZhouHdlCloudApi + "GetAllRegionEmqServerList";
#endregion
}
#region RequestObj 部分
///
/// BaseRequestObj
///
[System.Serializable]
public class BaseRequestObj
{
public string RequestVersion = MainPage.CodeIDString;
public string RequestSource = MainPage.RequestSource;
public string LoginAccessToken;
}
[System.Serializable]
public class ConfirmSelectEmqRegionRequestObj: BaseRequestObj
{
///
/// EMQ服务器Id
///
public string EmqServerId;
}
#endregion
#region ResponseData 部分
[Serializable]
public class EmqServerInfoRes
{
public string Id { get; set; }
public string EmqDomainOrIp { get; set; }
public bool IsCurrentSelect { get; set; }
}
[Serializable]
public class EmqServerListInfoRes
{
public List PageData = new List ();
}
#endregion
}