XSocket.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**************************************************************************************************
  2. 版本所有(C), 2020-2022, 北京普达迪泰
  3. ***************************************************************************************************
  4. 文 件 名: XSocket.h
  5. 功能描述: 封闭网络套接字通信
  6. 版 本 号: 1.00初版
  7. 作 者: HYF
  8. 生成日期; 2021-12-20
  9. 最近修改:
  10. 函数列表:
  11. 修改历史:
  12. 1.日 期 :2021-12-20
  13. 作 者 : HYF
  14. 修改内容 : 创建文件
  15. **************************************************************************************************/
  16. #pragma once
  17. #include "XEvent.h"
  18. #include <winsock2.h>
  19. #pragma comment (lib, "ws2_32.lib")
  20. enum
  21. {
  22. E_XSOCKET_SUCCESS,
  23. E_XSOCKET_TIMEDOUT,
  24. E_XSOCKET_ABORTED,
  25. E_XSOCKET_NOMOREDATA,
  26. E_XSOCKET_SOCKERR
  27. };
  28. class CXSocket
  29. {
  30. protected:
  31. SOCKET m_hSocket;
  32. CXEvent m_eventNet;
  33. CXEvent m_eventStop;
  34. int m_nLastError;
  35. public:
  36. CXSocket(void);
  37. CXSocket(SOCKET hSocket);
  38. ~CXSocket(void);
  39. bool Init();
  40. void Uninit();
  41. ////////////////////////////////////////////////////
  42. bool EventSelect();
  43. bool Connect(const char* pAddr, unsigned short uPort);
  44. bool QConnect(DWORD dwIP, unsigned short uPort);
  45. int Recv(char* pBuff, int nLen, int& nLenReceived, DWORD dwTimeOut = 0);
  46. int Send(const char* pBuff, int nLen, int& nLenSent, DWORD dwTimeOut = 0);
  47. long GetLenDataAvail();
  48. int GetLastError();
  49. void Close();
  50. void Abort();
  51. bool IsStopped();
  52. };