close
public static bool IsConnectingServer() { string serverAddress = Properties.Settings.Default.ServerAddress; try { HttpWebRequest request = (HttpWebRequest) WebRequest.Create( serverAddress ); request.Method = "HEAD"; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); return response.StatusCode == HttpStatusCode.OK; } catch ( Exception ) { return false; } }
參考:
Check whether a server is online using an IP and Port
Checking whether the server is on/off
文章標籤
全站熱搜
留言列表