升龙物业 老版本 ocx IPO, 加密狗 转值班电话

NetClient.h 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*************************************************************************
  2. 【文件名】 NetClient.h
  3. 【功能模块和目的】 网络客户端类头文件
  4. 【开发者及日期】 郑石诺 2015/07/19
  5. 【版本】 V1.0.0
  6. 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
  7. 【更改记录】
  8. *************************************************************************/
  9. #pragma once
  10. #include "socketbase.h"
  11. #include "ClientAssistant.h"
  12. class CPduEntity;
  13. /*************************************************************************
  14. 【类名】 CNetClient
  15. 【功能】
  16. 【接口说明】 网络客户端类
  17. 【开发者及日期】 郑石诺 2015/07/19
  18. 【版本】 V1.0.0
  19. 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司
  20. 【更改记录】
  21. *************************************************************************/
  22. class CNetClient : public CSocketBase
  23. {
  24. public:
  25. CNetClient(CNetLinkMain* pParent, PDU_LINK_TYPE a_nLinkType, bool IsAutoReconnect);
  26. virtual ~CNetClient(void);
  27. void doJob(OVERLAPPED* pOverLapped, DWORD BytesTransfered);
  28. bool isAlive(void);
  29. void onDisconnect(void);
  30. // SOCKET相关操作
  31. bool connect2Server(const CString& a_FarIp, int a_FarPort, PDU_DEV_TYPE a_FarType, int a_FarId); // 连接到SERVER端
  32. bool sendDirectly(CPduEntity* a_pCmd); // 发送PDU命令
  33. bool sendPdu(CPduEntity* a_pCmd); // 发送PDU命令
  34. bool regist(void); // 注册连接
  35. bool monitor(void); // 心跳监听
  36. bool ready4Recv(void);
  37. void drop(void);
  38. // 属性
  39. PDU_LINK_TYPE linkType(void) const { return m_Assistant.linkType(); } // 得到连接类型
  40. void getFarLinkInfo(CString& a_FarIp, int& a_FarPort) const { m_Assistant.getFarLinkInfo(a_FarIp, a_FarPort); } // 对端IP、端口号
  41. void setFarLinkInfo(LPCTSTR a_FarIp, int a_FarPort) { m_Assistant.setFarLinkInfo(a_FarIp, a_FarPort); }
  42. void getFarDevInfo(PDU_DEV_TYPE& a_DevType, int& a_DevId) const { m_Assistant.getFarDevInfo(a_DevType, a_DevId); } // 对端设备类型、ID
  43. void setFarDevInfo(PDU_DEV_TYPE a_DevType, int a_DevId) { m_Assistant.setFarDevInfo(a_DevType, a_DevId); }
  44. void getLocalInfo(PDU_DEV_TYPE& a_DevType, int& a_DevId) const; // 获取本端设备类型及ID
  45. // 事件响应处理
  46. void onConnEstablished(void) { m_Assistant.onConnEstablisthed(); } // 连接建立
  47. void onConnFailed(void) { m_Assistant.onConnFailed(); } // 连接失败/断开
  48. void onConnRegistOK(void) { m_Assistant.onConnRegistOK(); } // 注册成功
  49. void onConnRegistFailed(void) { m_Assistant.onConnRegistFailed(); } // 注册失败
  50. private:
  51. friend class CClientAssistant;
  52. void __resetBuffer(void);
  53. bool __create(void);
  54. bool __connect(LPCTSTR FarAddr, int FarPort);
  55. bool __send(UCHAR a_szBuf[], UINT a_BufLen);
  56. private:
  57. CClientAssistant m_Assistant;
  58. int m_HasRead; // 已读取的数据缓冲区长度
  59. OVERLAPPED m_Overlapped;
  60. WSABUF m_WsaBuf;
  61. char m_szBuffer[PDU_BUFFER_LEN];
  62. };