TCPClient.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef _CLIENT_SOCKET_H_
  2. #define _CLIENT_SOCKET_H_
  3. #include "TcpParse.h"
  4. #pragma warning(push)
  5. #pragma warning(disable:4995)
  6. #pragma warning(pop)
  7. #include "CritSection.h"
  8. #include "SocketHandle.h"
  9. #include "SocketClientImpl.h"
  10. const int TCPCLIENTNUM = 50;
  11. class CTCPClient: public CDialog, public ISocketClientHandler
  12. {
  13. typedef SocketClientImpl<ISocketClientHandler> CSocketClient;
  14. friend CSocketClient;
  15. protected:
  16. // ISocketServerHandler
  17. virtual void OnThreadBegin(CSocketHandle* pSH);
  18. virtual void OnThreadExit(CSocketHandle* pSH);
  19. virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr);
  20. virtual void OnConnectionDropped(CSocketHandle* pSH);
  21. virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError);
  22. void GetAddress(const SockAddrIn& addrIn, CString& rString) const;
  23. bool SetupMCAST();
  24. public:
  25. CTCPClient();
  26. ~CTCPClient();
  27. BOOL Connection(LPCTSTR strAddr, LPCTSTR strPort);
  28. void DisConnection(void);
  29. // 静态成员函数,提供全局访问的接口(给IDE调用)
  30. static CTCPClient* GetInstancePtr( int iTCPIndex );
  31. BOOL SendNoticeToServer( int iCmd,int iOperateType,CString sUserName,CString sUID,int iVarID );
  32. BOOL GetDogInfo();
  33. BOOL TestAlarm();
  34. BOOL ConfigAlarm( CString sUID,int iVarID,int iStatus,int iAlarmIndex );
  35. public :
  36. CSocketClient m_SocketClient;
  37. CTcpParse m_TcpParse;
  38. BOOL m_bSocket;
  39. void Release();
  40. private:
  41. enum { IDD = 10 };
  42. int m_nSockType; //UDP 或 TCP
  43. int m_nMode; //IP4 或 IP6
  44. // CTCPClient数组,在GetInstancePtr里创建成员;
  45. static CTCPClient *m_pTcpClient[TCPCLIENTNUM];
  46. };
  47. #endif