#pragma once #include #include #ifndef _WIN32 #include #include #include #include #include #include #include #include #define SOCKET int #define INVALID_SOCKET -1 #define SOCKET_ERROR -1 #else #include #include #pragma comment(lib,"Ws2_32.lib") #endif #include "IYUDPClient.h" #include "VrError.h" #define IP_ADDR_LEN 16 class CUDPClient : public IYUDPClient { public: CUDPClient(); ~CUDPClient(); /** * 初始化服务 * @brief Init * @return */ virtual int Init(const bool bBoard); /** * 开始接收UDP数据 * @brief StartUDPClient * @return */ virtual int StartUDPClient(UdpClientRecvDataFunc pRecvDataFunc); /** * 结束接收UDP数据 * @brief StopUDPClient * @return */ virtual int StopUDPClient(); /** * 发送数据 * @brief SendData * @param pData * @param nLen * @return */ virtual int SendData(const int nPort, const char* pAddr, const char* pData, const int nLen); private: void _CloseSocket(); void _UdpRecvData(); private: SOCKET m_sockfd; sockaddr_in m_sin_from; std::atomic_bool m_bRecv; std::atomic_bool m_bRecvRuning; UdpClientRecvDataFunc m_funcRecvData; };