IClientImpl.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*************************************************************
  2. /* Copyright (C), 2014-2020, lyfz. Co., Ltd.
  3. /* 文件名: IClientImpl.h
  4. /* 作者: Jeff.w
  5. /* 创建日期: 2014-08-07
  6. /* 版本号: V1.0
  7. /* 描述: 核心层底,客户端与服务端通信接口
  8. /* 其它:
  9. /* 主要类模块:
  10. /* 历史修改记录:
  11. /* 作者 时间 版本 描述
  12. /* Jeff.w 14/08/07 1.0 创建这个模块
  13. ***************************************************************/
  14. #ifndef __ICLIENT_IMPL_HEADER__
  15. #define __ICLIENT_IMPL_HEADER__
  16. #pragma once
  17. #include <afxwin.h>
  18. #include <atlbase.h>
  19. //#pragma warning(push)
  20. //#pragma warning(disable:4995)
  21. //#pragma warning(pop)
  22. #include "CritSection.h"
  23. #include "SocketHandle.h"
  24. #include "SocketClientImpl.h"
  25. #include "Global.h"
  26. // 宏定义:计算数据包总长度;
  27. #define CALCDATALEN(x) (x+sizeof(STProtocolheader)+sizeof(STProtocoltail))
  28. //const int TCPCLIENTNUM = 10;
  29. class IClientImpl : public ISocketClientHandler
  30. {
  31. typedef SocketClientImpl<ISocketClientHandler> CSocketClient;
  32. friend CSocketClient;
  33. public:
  34. IClientImpl();
  35. ~IClientImpl();
  36. //static IClientImpl* GetInstancePtr( int iTCPIndex );
  37. void StartReConnectSrvThread();
  38. static DWORD WINAPI ReConnectSrvThread(LPVOID pInstance);
  39. protected:
  40. virtual void OnThreadBegin(CSocketHandle* pSH);
  41. virtual void OnThreadExit(CSocketHandle* pSH);
  42. virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr);
  43. virtual void OnConnectionDropped(CSocketHandle* pSH);
  44. virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError);
  45. protected:
  46. CString m_strPort;
  47. int m_nMode; // IPV4 或 IPV6
  48. int m_nSockType; // UDP 或 TCP
  49. // 线程句柄;
  50. HANDLE m_hReConnectSrvThreadHandle;
  51. // 线程退出句柄;
  52. HANDLE m_hRunObject;
  53. //static IClientImpl *m_pTcpClient[TCPCLIENTNUM];
  54. void _cdecl AppendText(LPCTSTR lpszFormat, ...);
  55. void GetAddress(const SockAddrIn& addrIn, CString& rString) const;
  56. bool GetDestination(SockAddrIn& addrIn) const;
  57. bool SetupMCAST();
  58. // Jeff.最新研究出来的处理方案;
  59. // 对异常包需要计数处理,当1分钟内出现多少异常包时,需要重启服务函数;
  60. //unsigned int VerityIntegrityPacket(IN void *pIntegrityPacket,unsigned int nPacketSize);
  61. void ToprocessRecivebuf(IN CSocketHandle *sockHandle, IN const BYTE* pReceivebuf, IN DWORD dwReceiveSize);
  62. int OnIntegrityPacket(IN CSocketHandle *sockHandle, IN void *pIntegrityPacket);
  63. public:
  64. BOOL m_bStopbeat; // 是否心跳包;
  65. BOOL m_bSocket;
  66. CSocketClient m_SocketClient;
  67. BOOL Initialize();
  68. BOOL ConnectServer(LPCTSTR strAddr, LPCTSTR strPort);
  69. void DisConnectServer();
  70. void SendMsg(void *pMsg,const int nLen);
  71. void SendFile(LPCTSTR lpzFileName,LPCTSTR strPort);
  72. };
  73. #endif