/************************************************************************* 【文件名】 NetClient.h 【功能模块和目的】 网络客户端类头文件 【开发者及日期】 郑石诺 2015/07/19 【版本】 V1.0.0 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司 【更改记录】 *************************************************************************/ #pragma once #include "socketbase.h" #include "ClientAssistant.h" class CPduEntity; /************************************************************************* 【类名】 CNetClient 【功能】 【接口说明】 网络客户端类 【开发者及日期】 郑石诺 2015/07/19 【版本】 V1.0.0 【版权信息】 Copyright (C)2015 河南华谊网络科技有限公司 【更改记录】 *************************************************************************/ class CNetClient : public CSocketBase { public: CNetClient(CNetLinkMain* pParent, PDU_LINK_TYPE a_nLinkType, bool IsAutoReconnect); virtual ~CNetClient(void); void doJob(OVERLAPPED* pOverLapped, DWORD BytesTransfered); bool isAlive(void); void onDisconnect(void); // SOCKET相关操作 bool connect2Server(const CString& a_FarIp, int a_FarPort, PDU_DEV_TYPE a_FarType, int a_FarId); // 连接到SERVER端 bool sendDirectly(CPduEntity* a_pCmd); // 发送PDU命令 bool sendPdu(CPduEntity* a_pCmd); // 发送PDU命令 bool regist(void); // 注册连接 bool monitor(void); // 心跳监听 bool ready4Recv(void); void drop(void); // 属性 PDU_LINK_TYPE linkType(void) const { return m_Assistant.linkType(); } // 得到连接类型 void getFarLinkInfo(CString& a_FarIp, int& a_FarPort) const { m_Assistant.getFarLinkInfo(a_FarIp, a_FarPort); } // 对端IP、端口号 void setFarLinkInfo(LPCTSTR a_FarIp, int a_FarPort) { m_Assistant.setFarLinkInfo(a_FarIp, a_FarPort); } void getFarDevInfo(PDU_DEV_TYPE& a_DevType, int& a_DevId) const { m_Assistant.getFarDevInfo(a_DevType, a_DevId); } // 对端设备类型、ID void setFarDevInfo(PDU_DEV_TYPE a_DevType, int a_DevId) { m_Assistant.setFarDevInfo(a_DevType, a_DevId); } void getLocalInfo(PDU_DEV_TYPE& a_DevType, int& a_DevId) const; // 获取本端设备类型及ID // 事件响应处理 void onConnEstablished(void) { m_Assistant.onConnEstablisthed(); } // 连接建立 void onConnFailed(void) { m_Assistant.onConnFailed(); } // 连接失败/断开 void onConnRegistOK(void) { m_Assistant.onConnRegistOK(); } // 注册成功 void onConnRegistFailed(void) { m_Assistant.onConnRegistFailed(); } // 注册失败 private: friend class CClientAssistant; void __resetBuffer(void); bool __create(void); bool __connect(LPCTSTR FarAddr, int FarPort); bool __send(UCHAR a_szBuf[], UINT a_BufLen); private: CClientAssistant m_Assistant; int m_HasRead; // 已读取的数据缓冲区长度 OVERLAPPED m_Overlapped; WSABUF m_WsaBuf; char m_szBuffer[PDU_BUFFER_LEN]; };