Created
August 6, 2018 01:47
-
-
Save st0326s/d63c02ec37123616976f8f23a55fb08f to your computer and use it in GitHub Desktop.
Unity 通信状態の取得 ref: https://qiita.com/satotin/items/e26787254eaec1fa3be4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Pingによる応答時間の取得 | |
/// </summary> | |
public async void OnClickGetPingTime() | |
{ | |
int pingTime = await PingStatus.GetPingTime(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// 通信状態の取得クラス | |
/// </summary> | |
public static class PingStatus | |
{ | |
/// <summary> | |
/// PING応答時間の取得 | |
/// </summary> | |
/// <returns>PING応答時間(msec)</returns> | |
public static async Task<int> GetPingTime() | |
{ | |
// "/"を省いたホスト名にする事 | |
string host = ""; | |
// ホスト名からIPアドレスを非同期で取得 | |
IPAddress[] serverIPs = await Dns.GetHostAddressesAsync(host); | |
// コンストラクタが走った時点でPING送信される | |
Ping ping = new Ping(serverIPs[0].ToString()); | |
await new WaitUntil(() => ping.isDone == true); | |
return ping.time; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment