| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- /**************************************************************************************************
- 版本所有(C), 2020-2022, 北京普达迪泰
- ***************************************************************************************************
- 文 件 名: XSocket.h
- 功能描述: 封闭网络套接字通信
- 版 本 号: 1.00初版
- 作 者: HYF
- 生成日期; 2021-12-20
- 最近修改:
- 函数列表:
- 修改历史:
- 1.日 期 :2021-12-20
- 作 者 : HYF
- 修改内容 : 创建文件
- **************************************************************************************************/
- #pragma once
- #include "XEvent.h"
- #include <winsock2.h>
- #pragma comment (lib, "ws2_32.lib")
- enum
- {
- E_XSOCKET_SUCCESS,
- E_XSOCKET_TIMEDOUT,
- E_XSOCKET_ABORTED,
- E_XSOCKET_NOMOREDATA,
- E_XSOCKET_SOCKERR
- };
- class CXSocket
- {
- protected:
- SOCKET m_hSocket;
- CXEvent m_eventNet;
- CXEvent m_eventStop;
- int m_nLastError;
- public:
- CXSocket(void);
- CXSocket(SOCKET hSocket);
- ~CXSocket(void);
- bool Init();
- void Uninit();
- ////////////////////////////////////////////////////
- bool EventSelect();
- bool Connect(const char* pAddr, unsigned short uPort);
- bool QConnect(DWORD dwIP, unsigned short uPort);
- int Recv(char* pBuff, int nLen, int& nLenReceived, DWORD dwTimeOut = 0);
- int Send(const char* pBuff, int nLen, int& nLenSent, DWORD dwTimeOut = 0);
-
- long GetLenDataAvail();
- int GetLastError();
-
- void Close();
- void Abort();
- bool IsStopped();
- };
|