From 0d75f701778a0900a58343c4c80c124279bc231f Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 11 Jun 2017 07:41:07 -0400 Subject: skip server connection if server is offline --- ShiftOS_TheReturn/ServerManager.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'ShiftOS_TheReturn/ServerManager.cs') diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index be4f086..00f9653 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -38,6 +38,7 @@ using System.Net.Sockets; using System.Diagnostics; using System.IO; using System.Reflection; +using System.Net.NetworkInformation; namespace ShiftOS.Engine { @@ -46,6 +47,29 @@ namespace ShiftOS.Engine /// public static class ServerManager { + + public static bool ServerOnline + { + get + { + try + { + Ping myPing = new Ping(); + String host = UserConfig.Get().DigitalSocietyAddress; + byte[] buffer = new byte[32]; + int timeout = 1000; + PingOptions pingOptions = new PingOptions(); + PingReply reply = myPing.Send(host, timeout, buffer, pingOptions); + return (reply.Status == IPStatus.Success); + } + catch (Exception) + { + return false; + } + } + } + + /// /// Print connection diagnostic information. /// -- cgit v1.2.3