#pragma once #include #include #include #include #include #include #ifdef _WIN32 #define _WINSOCK_DEPRECATED_NO_WARNINGS #include #pragma comment(lib,"Ws2_32.lib") #pragma comment(lib, "UDPServer.lib") #else #include #include #endif typedef std::function UdpRecvDataFunc; class IYUDPServer { public: virtual ~IYUDPServer() = default; /** * 创建对象 */ static bool VrCreateUDPServer(IYUDPServer** ppIUDPServer); /** * 初始化服务 * @brief Init * @return */ virtual int Init(const int nPort) = 0; /** * 开始接收UDP数据 * @brief StartUDPServer * @return */ virtual int StartUDPServer(UdpRecvDataFunc pRecvDataFunc, bool bRecvSelfProtocol) = 0; /** * 结束接收UDP数据 * @brief StopUDPServer * @return */ virtual int StopUDPServer() = 0; /** * 发送数据 * @brief SendData * @param pData * @param nLen * @return */ virtual int SendData(const sockaddr_in clientPeer, const char* pData, const int nLen) = 0; };