【源碼目錄】
E_7_2_3_1
├── Debug
│ ├── E_7_2_3_1.exe
│ ├── E_7_2_3_1.ilk
│ ├── E_7_2_3_1.obj
│ ├── E_7_2_3_1.opt
│ ├── E_7_2_3_1.pch
│ ├── E_7_2_3_1.pdb
│ ├── E_7_2_3_1.res
│ ├── E_7_2_3_1Dlg.obj
│ ├── E_7_2_3_1Dlg.pdb
│ ├── StdAfx.obj
│ ├── vc60.idb
│ └── vc60.pdb
├── E_7_2_3_1.APS
├── E_7_2_3_1.clw
├── E_7_2_3_1.cpp
├── E_7_2_3_1.dsp
├── E_7_2_3_1.dsw
├── E_7_2_3_1.h
├── E_7_2_3_1.ncb
├── E_7_2_3_1.opt
├── E_7_2_3_1.plg
├── E_7_2_3_1.rc
├── E_7_2_3_1Dlg.cpp
├── E_7_2_3_1Dlg.dsp
├── E_7_2_3_1Dlg.dsw
├── E_7_2_3_1Dlg.h
├── E_7_2_3_1Dlg.ncb
├── E_7_2_3_1Dlg.opt
├── E_7_2_3_1Dlg.plg
├── ReadMe.txt
├── StdAfx.cpp
├── StdAfx.h
├── res http://www.jingjixx.com/
│ ├── E_7_2_3_1.ico
│ └── E_7_2_3_1.rc2
└── resource.h
2 directories, 35 files
【核心代碼】
void CE_7_2_3_1Dlg::OnConnect() { // TODO: Add your control notification handler code here UpdateData(true); WSADATA WSAData; if(WSAStartup(MAKEWORD(2,2),&WSAData)!=0) { MessageBox("初始化Winsock失敗!"); return; } SocketControl=socket(AF_INET,SOCK_STREAM,0); if(SocketControl==INVALID_SOCKET) { MessageBox("創(chuàng)建控制Scoket失敗!"); WSACleanup(); return; } int IpAddress; IpAddress=inet_addr(m_Address); if(IpAddress==INADDR_NONE) { hostent* pHostent=gethostbyname(m_Address); if(pHostent) IpAddress=(*(in_addr*)pHostent->h_addr).s_addr; } sockaddr_in serveraddr; memset(&serveraddr,0,sizeof(serveraddr)); serveraddr.sin_family=AF_INET; serveraddr.sin_port=htons(21); serveraddr.sin_addr.s_addr=IpAddress; m_Login ="Client: Connet to "; m_Login =m_Address; m_Login ="...\r\n"; UpdateData(false); int nConnect; nConnect=connect(SocketControl,(sockaddr*)&serveraddr,sizeof(serveraddr)); if(nConnect==SOCKET_ERROR) { MessageBox("控制鏈接建立失敗!"); closesocket(SocketControl); WSACleanup(); return; } if(!RecvRespond()) return; else { if(RespondCode==220) { m_Login ="Server: "; m_Login =Respond; } else { MessageBox("控制鏈接響應錯誤!"); closesocket(SocketControl); WSACleanup(); return; } } memset(Command,0,MAX_SIZE); memcpy(Command,"USER ",strlen("USER ")); memcpy(Command strlen("USER "),m_Account,strlen(m_Account)); memcpy(Command strlen("USER ") strlen(m_Account),"\r\n",2); if(!SendCommand()) return; m_Login ="Client: "; m_Login =Command; if(!RecvRespond()) return; else { if(RespondCode==220||RespondCode==331) { m_Login ="Server: "; m_Login =Respond; } else { MessageBox("USER 響應錯誤!"); closesocket(SocketControl); WSACleanup(); return; } } if(RespondCode==331) { memset(Command,0,MAX_SIZE); memcpy(Command,"PASS ",strlen("PASS ")); memcpy(Command strlen("PASS "),m_Password,strlen(m_Password)); memcpy(Command strlen("PASS ") strlen(m_Password),"\r\n",2); if(!SendCommand()) return; m_Login ="Client: PASS ******\r\n"; UpdateData(false); if(!RecvRespond()) return; else { if(RespondCode==230) { m_Login ="Server: "; m_Login =Respond; } else { MessageBox("PASS 響應錯誤!"); closesocket(SocketControl); WSACleanup(); return; } } } UpdateData(false); }