ClientSocket.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <afxwin.h>
  3. #include <atlbase.h>
  4. #include "SocketHandle.h"
  5. #include "SocketClientImpl.h"
  6. #include "head.h"
  7. class CClientSocket:public CDialog, public ISocketClientHandler
  8. {
  9. typedef SocketClientImpl<ISocketClientHandler> CSocketClient;
  10. friend CSocketClient;
  11. protected:
  12. // SocketClient Interface handler
  13. virtual void OnThreadBegin(CSocketHandle* pSH);
  14. virtual void OnThreadExit(CSocketHandle* pSH);
  15. virtual void OnDataReceived(CSocketHandle* pSH, const BYTE* pbData, DWORD dwCount, const SockAddrIn& addr);
  16. virtual void OnConnectionDropped(CSocketHandle* pSH);
  17. virtual void OnConnectionError(CSocketHandle* pSH, DWORD dwError);
  18. protected:
  19. private:
  20. bool GetDestination(SockAddrIn& addrIn) const;
  21. int ReadDataRes(char *pTmpData);
  22. int WriteDataRes(char *pData);
  23. int ReadDataResError(char *pData);
  24. int WriteDataResError(char *pData);
  25. public:
  26. int ClientSend(char* pMsg, int iLen);
  27. BOOL Connection(LPCTSTR strAddr, LPCTSTR strPort);
  28. void DisConnection(void);
  29. bool SetupMCAST();
  30. void GetAddress(const SockAddrIn& addrIn, CString& rString) const;
  31. void ProcessData(CSocketHandle *pSH, const BYTE* pData, DWORD nLen);
  32. int OnCmdProcess(void *pData, int iDataLen);
  33. static DWORD WINAPI ReConnectSrvThread( void *pData );
  34. public:
  35. int WorkMain(REQUESTPARAM SetBasePara);
  36. int Write(REQUESTWRPARAM writeParam);
  37. int RequestStatus(void *pData, int nLen);
  38. public:
  39. CClientSocket(void);
  40. ~CClientSocket(void);
  41. public:
  42. HANDLE m_hSemNet;
  43. int m_nSockType; //UDP »ò TCP
  44. int m_nMode; //IP4 »ò IP6
  45. BOOL m_bSocket;
  46. CSocketClient m_SocketClient;
  47. HANDLE m_hReConnectSrvThread;
  48. HANDLE m_hRunObject;
  49. char m_chIpAddr[32];
  50. int m_nNetPort;
  51. public:
  52. RESPONSE_STRUCT m_structResponse;
  53. WRITESUCCESSRESPONSE m_structWriteResponse;
  54. };