資源簡介
一個用MFC開發的FTP客戶端,特點是支持多線程下載和斷點續傳,沒有用CSocket,用了比較底層的Socket函數,適合學習Socket的朋友,請多多支持

代碼片段和文件信息
//?client.cpp?:?Defines?the?class?behaviors?for?the?application.
//
#include?“stdafx.h“
#include?“client.h“
#include?“afxsock.h“
#include?“MainFrm.h“
#include?“clientDoc.h“
#include?“clientView.h“
#ifdef?_DEBUG
#define?new?DEBUG_NEW
#undef?THIS_FILE
static?char?THIS_FILE[]?=?__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//?CClientApp
BEGIN_MESSAGE_MAP(CClientApp?CWinApp)
//{{AFX_MSG_MAP(CClientApp)
ON_COMMAND(ID_APP_ABOUT?OnAppAbout)
//?NOTE?-?the?ClassWizard?will?add?and?remove?mapping?macros?here.
//????DO?NOT?EDIT?what?you?see?in?these?blocks?of?generated?code!
//}}AFX_MSG_MAP
//?Standard?file?based?document?commands
ON_COMMAND(ID_FILE_NEW?CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN?CWinApp::OnFileOpen)
//?Standard?print?setup?command
ON_COMMAND(ID_FILE_PRINT_SETUP?CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//?CClientApp?construction
CClientApp::CClientApp()
{
//?TODO:?add?construction?code?here
//?Place?all?significant?initialization?in?InitInstance
}
/////////////////////////////////////////////////////////////////////////////
//?The?one?and?only?CClientApp?object
CClientApp?theApp;
//完成進線
DWORD?WINAPI?notify(LPVOID?lpparam)
{
CMainframe*??pthis=(CMainframe*)lpparam;
return?pthis->Finish();
}
DWORD?WINAPI?timethread(LPVOID?lpparam)
{
//記錄進程
CDownLoad?*?pthis=(CDownLoad?*)lpparam;
return?pthis->Finish();
}
int?Rev(SOCKET?sockchar?*dataint?len)
{
//取數據
int?iLenGettedret;
iLenGetted=len;
while(iLenGetted>0)
{
ret=recv(sockdataiLenGetted0);
if(ret<0)
{
CString?str;
????????????str=“接收錯誤\n“;
????????????AfxGetMainWnd()->SendMessageToDescendants(WM_MESSAGE?(WPARAM)str.GetBuffer(0)(LPARAM)RGB(25500)1);
str.ReleaseBuffer();
return?-2;
}
if(ret==0)
return?len-iLenGetted;
data+=ret;
iLenGetted-=ret;
}
return?len;
}
int?Send(SOCKET?sockchar?*dataint?len)
{
//發送信息
int?iLenSendedret;
iLenSended=len;
while(iLenSended>0)
{
ret=send(sockdataiLenSended0);
if(ret<0)
{
CString?str;
????????????str=“發送錯誤\n“;
????????????AfxGetMainWnd()->SendMessageToDescendants(WM_MESSAGE?(WPARAM)str.GetBuffer(0)(LPARAM)RGB(25500)1);
str.ReleaseBuffer();
return?-2;
}
if(ret==0)
return?len-iLenSended;
data+=ret;
iLenSended-=ret;
}
return?len;
}
//下載進程
DWORD?WINAPI?DownLoadThread(LPVOID?lpparam)
{
CDownLoad?*?pthis=(CDownLoad*)lpparam;
InterlockedIncrement(&pthis->m_index);
pthis->DownThread(pthis->m_index-1);
return?1;
}
CString?g_IP;
int?fileflags[10];
FILEINFO?files[10];
/////////////////////////////////////////////////////////////////////////////
//?CClientApp?initialization
BOOL?CClientApp::InitInstance()
{
if?(!AfxSocketInit())?????????????????????????//重要
{
AfxMessageBox(IDP_SOC
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????49280??2010-12-23?14:07??client\client.aps
?????文件???????4015??2011-02-28?21:39??client\client.clw
?????文件???????6295??2010-12-23?13:31??client\client.cpp
?????文件???????5140??2010-12-23?14:47??client\client.dsp
?????文件????????520??2010-12-22?23:00??client\client.dsw
?????文件???????1591??2010-12-23?13:04??client\client.h
?????文件??????82944??2011-02-28?21:39??client\client.ncb
?????文件??????50688??2011-02-28?21:39??client\client.opt
?????文件????????246??2010-12-29?22:11??client\client.plg
?????文件??????16019??2010-12-23?14:07??client\client.rc
?????文件???????2468??2010-12-22?23:00??client\clientDoc.cpp
?????文件???????1547??2010-12-22?23:00??client\clientDoc.h
?????文件???????4798??2010-12-24?13:18??client\clientView.cpp
?????文件???????2002??2010-12-22?23:41??client\clientView.h
?????文件???????1111??2010-12-22?23:00??client\CntrItem.cpp
?????文件???????1554??2010-12-22?23:00??client\CntrItem.h
?????文件????5907456??2010-12-23?01:40??client\Debug\client.bsc
?????文件????2408500??2010-12-24?14:29??client\Debug\client.exe
?????文件????2817864??2010-12-24?14:29??client\Debug\client.ilk
?????文件??????30976??2010-12-23?13:31??client\Debug\client.obj
?????文件????6130884??2010-12-23?01:45??client\Debug\client.pch
?????文件????4531200??2010-12-24?14:29??client\Debug\client.pdb
?????文件??????22664??2010-12-23?14:07??client\Debug\client.res
?????文件??????????0??2010-12-23?01:40??client\Debug\client.sbr
?????文件??????19869??2010-12-23?13:04??client\Debug\clientDoc.obj
?????文件??????????0??2010-12-23?00:26??client\Debug\clientDoc.sbr
?????文件??????32915??2010-12-24?13:18??client\Debug\clientView.obj
?????文件??????????0??2010-12-23?01:03??client\Debug\clientView.sbr
?????文件??????15743??2010-12-23?13:04??client\Debug\CntrItem.obj
?????文件??????????0??2010-12-23?00:26??client\Debug\CntrItem.sbr
............此處省略35個文件信息
評論
共有 條評論