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;
    }
}

來源:C# Check Remote Server

參考:
Check whether a server is online using an IP and Port
Checking whether the server is on/off

 

 

arrow
arrow
    創作者介紹
    創作者 Robert 的頭像
    Robert

    Robert 的部落格

    Robert 發表在 痞客邦 留言(0) 人氣()