By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,704 Members | 1,076 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,704 IT Pros & Developers. It's quick & easy.

how to connect Alternate down load server using vc++

P: 1
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;
}
Apr 16 '07 #1
Share this Question
Share on Google+
1 Reply


MMcCarthy
Expert Mod 10K+
P: 14,534
This question is being moved to the C++ forum.

ADMIN
Apr 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.