資源簡介
c++編寫的smtp和pop3服務器實現,簡單小巧,運行流暢,支持多客戶端。

代碼片段和文件信息
/*****************************************************************************************************
Program?File?Name:?popserver.cpp
Program?Begin?Date:?2007-4-16
Program?Description:?A?Simple?pop3?server
Author:?wangjianlin
*****************************************************************************************************/
#include?
#include?
#include?
#include?
#pragma?comment(lib?“ws2_32.lib“)?
/*****************************************************************************************************/
#define?MAX_CONNECTION_NUM?50?????????//定義最大連接數
#define?POP_SERVER_PORT?110??????????//定義服務器端口
#define?BUFFER_SIZE?1024?????????????//定義緩沖區大小
/*****************************************************************************************************/
u_short?serverPort=POP_SERVER_PORT;?????????????????????//定義服務器端口為默認端口
char?*readBuf;???????????????????????????????????????????//定義接受數據緩沖區
WSAData?wsaData;?????????????????????????????????????????//定義WSAData結構
SOCKET?clientSocket[MAX_CONNECTION_NUM];?????????????????//定義所有客戶端socket
SOCKET?serverSocket;?????????????????????????????????????//定義服務器監聽socket
struct?sockaddr_in?clientSockAddr[MAX_CONNECTION_NUM];???//定義所有客戶端信息
struct?sockaddr_in?server;???????????????????????????????//保存要設置的服務器信息
/*****************************************************************************************************/
struct?UserInfo??????????????????????????????????????????//定義用戶信息結構
{???????????????????????????????????????????????????????
? char?username[20];???????????????????????????????????//用戶名
char?password[30];???????????????????????????????????//密碼
};
struct?ClientContent?????????????????????????????????????//客戶端輸入的信息????????????????????????
{
char?command[10];????????????????????????????????????//保存命令字符串
char?*param;?????????????????????????????????????????//指向命令參數
};
struct?CommandFinished???????????????????????????????????//命令執行狀態結構共2條命令
{
char?USER;???????????????????????????????????????????//如果該命令已經成功執行的話
char?PASS;???????????????????????????????????????????//就為字符‘Y‘否則為0
};
/*****************************************************************************************************/
DWORD?WINAPI?PopBeginService(LPVOID?lpParam);????????????//對客戶進行服務的函數,其中lpParam傳入服務Socket序號
void?WriteClientInfo(int?index);?????????????????????????//index為傳入的客戶Socket序號
void?CommandHandle(int?index);???????????????????????????//對index位置的客戶命令進行處理
void?GetCommandAndContent(char?*bufClientContent?*clientContent);?//分析buf指向的信息為命令和參數
int?GetFileSize(char?*fileNamestruct?UserInfo?*userInfo);?//得到文件fileName的大小
int?GetMailFileTotalSize(UserInfo?*userInfo);???????????//得到某個用戶郵件總大小
int?GetMailFileNum(UserInfo?*userInfo);??????????????????//得到某個用戶郵件數目
void?SortMailFile(UserInfo?*userInfo);??????????????????//對刪除后的郵件重新排序
void?USER_Handle(int?indexCommandFinished?*commandFinishedchar?*paramUserInfo?*userInfo);?//處理USER命令
void?PASS_Handle(int?indexCommandF
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????43401??2007-05-12?17:51??MailSystemServer\popserver.cpp
?????文件??????43323??2007-05-12?16:23??MailSystemServer\smtpserver.cpp
?????文件??????15223??2007-05-14?20:41??MailSystemServer\TestSMTP\Debug\hao.obj
?????文件?????170476??2007-05-14?20:41??MailSystemServer\TestSMTP\Debug\KEHU.ilk
?????文件????3645260??2007-04-23?14:13??MailSystemServer\TestSMTP\Debug\KEHU.pch
?????文件?????508928??2007-05-14?20:41??MailSystemServer\TestSMTP\Debug\KEHU.pdb
?????文件?????164864??2007-05-14?20:43??MailSystemServer\TestSMTP\Debug\vc60.idb
?????文件??????86016??2007-05-14?20:41??MailSystemServer\TestSMTP\Debug\vc60.pdb
?????文件???????4259??2007-04-10?15:58??MailSystemServer\TestSMTP\KEHU.dsp
?????文件????????533??2007-04-10?15:38??MailSystemServer\TestSMTP\KEHU.dsw
?????文件??????41984??2007-05-14?20:44??MailSystemServer\TestSMTP\KEHU.ncb
?????文件??????48640??2007-05-14?20:44??MailSystemServer\TestSMTP\KEHU.opt
?????文件???????1240??2007-05-14?20:41??MailSystemServer\TestSMTP\KEHU.plg
?????文件?????????24??2007-04-10?21:36??MailSystemServer\TestSMTP\ServerLog.txt
?????文件???????3294??2007-05-14?20:41??MailSystemServer\TestSMTP\testSMTP.cpp
?????文件??????????0??2007-05-13?21:58??MailSystemServer\user.dat
?????目錄??????????0??2007-04-10?15:38??MailSystemServer\TestSMTP\Debug
?????目錄??????????0??2007-04-10?15:38??MailSystemServer\TestSMTP
?????目錄??????????0??2007-05-23?21:11??MailSystemServer
-----------?---------??----------?-----??----
??????????????4777465????????????????????19
評論
共有 條評論