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 發表在 痞客邦 留言(0) 人氣()