C++判断是否连接服务器

BOOL CheckServerStatus::isConnectServer(CString serverName, int serverPort)
{
	CString strURL;
	strURL.Format("http://%s:%d", serverName, serverPort);
	BOOL hSession = GetSession(strURL);
	return hSession;
}
BOOL CheckServerStatus::GetSession(CString URL)
{
	HINTERNET hInternet = InternetOpen(NULL, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL);
	if (NULL == hInternet)
	{
		InternetCloseHandle(hInternet);
		return FALSE;
	}
	DWORD options = INTERNET_FLAG_NEED_FILE | INTERNET_FLAG_HYPERLINK | INTERNET_FLAG_RESYNCHRONIZE | INTERNET_FLAG_RELOAD;
	HINTERNET hInternetUrl = InternetOpenUrl(hInternet, URL, NULL, NULL, options, NULL);
	if (NULL == hInternetUrl)
	{
		return FALSE;
	}
	InternetCloseHandle(hInternet);
	InternetCloseHandle(hInternetUrl);
	return TRUE;
}

  

posted @ 2017-04-06 16:54  一样菜  阅读(1691)  评论(0编辑  收藏  举报