Hi this is krishna
I have two download servers . If one server is busy or not find then I have to connect alternate download server. already i have example code using this we can connect download server . plz any body help me
CString strURL;
CString strPort;
CString strPath;
CString strAffiliateID;
mapURLs.Lookup(_T("DownloadServer"),strURL);
mapURLs.Lookup(_T("DownloadServerPort"),strPort);
mapURLs.Lookup(_T("DownloadServerPath"),strPath);
mapURLs.Lookup(_T("AffiliateID"),strAffiliateID);
CString compData = _T("");
int nDownloaded = 0; // Downloaded complete verifier
CInternetSession netSession;
TCHAR filebuf[513];
CStdioFile *pTargFile = NULL;
CString upgrade_file;
upgrade_file.Format(_T("http://%s:%s%s%s_comp.ver"),
strURL,
strPort,
strPath,
strAffiliateID
);
//AfxMessageBox(upgrade_file);
//Sleep(500);
try {
pTargFile = netSession.OpenURL(upgrade_file,
1,
INTERNET_FLAG_TRANSFER_BINARY |
INTERNET_FLAG_RELOAD);
nDownloaded = 1; // File has been found, downloading starts
//int byteswrite; // Number of bytes to write into the file
filebuf[0]=0;
//AfxMessageBox("before while");
int bytesread = 0;
while(bytesread = pTargFile->Read(filebuf,512)){
filebuf[bytesread]=0;
compData += filebuf;
filebuf[0]=0;
}
} catch(CInternetException *ie) {
//AfxMessageBox("CInternetException");
nDownloaded = 0;
CString strerror; // String variable
TCHAR error[256]; // Error message buffer
ie->GetErrorMessage(error,255); // Get error message
strerror = error; // Transfer into the CString object
if(pTargFile != NULL) {
delete pTargFile;
pTargFile = NULL;
}
ie->Delete();
compData.Empty();
return compData;
}
if(pTargFile != NULL) {
delete pTargFile;
pTargFile = NULL;
}
//AfxMessageBox(compData);
return compData;
}