#pragma once #include"protocol.h" #include #include #include #include "Configuration.h" #include "MsgProcess.h" using namespace std; typedef map FileMap; typedef std::vector< wstring > SelectedFileStats; class IPMsg { private: SOCKET udp_skt; SOCKET tcp_skt; string sender; char* hostname; int _packetNo; FileMap fileMap; MsgProcess* msgProcess; HANDLE recv_thread_hwnd; HANDLE listen_thread_hwnd; Configuration* pConfig; int LocalNewLineToUnix(const char *src, char *dest, int maxlen); int UnixNewLineToLocal(const char *src, char *dest, int maxlen); void CloseSocket(); void WSockTerm(); void UdpRecv(RecvBuf *buf); int AddFileToSendList(wstring&); //消息接收及处理线程 static DWORD WINAPI Recv_Thread(LPVOID param); static DWORD WINAPI Listen_Thread(LPVOID param); static DWORD WINAPI SendFile_Thread(LPVOID param); void DoSendFile(SOCKET s, wstring& fileName); void DoSendDirectory (SOCKET s, wstring& dir); void DoProcessDirfileData (SOCKET s,wstring& path, WIN32_FIND_DATA& dirData); public: int default_port; ULONG IPMsg::MakeMsg(char *buf, ULONG command, const char *msg, const char *exMsg, int *packet_len); ULONG MakeMsg(char *buf, int _packetNo, ULONG command, const char *msg, const char *exMsg, int *packet_len); IPMsg(void); ~IPMsg(void); void entry(); void exit(); BOOL ResolveMsg(RecvBuf *buf, MsgBuf *msg); inline int SendCommand(ULONG host,ULONG command, const char* msg = NULL, const char* exMsg=NULL) { return SendCommand(host, this->default_port, command , msg, exMsg); }; inline int SendCommand(ULONG host, int port,ULONG command, const char* msg = NULL, const char* exMsg=NULL) { return SendCommand(host, this->default_port, this->_packetNo ++, command, msg, exMsg); }; int SendCommand(ULONG host, int port,int _packgeNo, ULONG command, const char* msg = NULL, const char* exMsg=NULL); BOOL Recv(MsgBuf *msg); void setMsgProcess(MsgProcess* process){ this->msgProcess = process; } int NotifyToSendFile(vector& fileList,HostSub &host); }; struct Client { SOCKET cltskt; IPMsg* ipMsg; };