60 lines
1.0 KiB
C++
60 lines
1.0 KiB
C++
#pragma once
|
|
#include <cstdio>
|
|
#include <iostream>
|
|
|
|
#include <cstring>
|
|
#include <thread>
|
|
#include <functional>
|
|
#include <chrono>
|
|
|
|
#ifdef _WIN32
|
|
#define _WINSOCK_DEPRECATED_NO_WARNINGS
|
|
#include <WinSock2.h>
|
|
#else
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#endif
|
|
|
|
typedef std::function<void(const sockaddr_in serverPeer,const char* pData, const int nLen)> UdpClientRecvDataFunc;
|
|
|
|
class IYUDPClient
|
|
{
|
|
public:
|
|
|
|
virtual ~IYUDPClient() = default;
|
|
|
|
// 创建对象
|
|
static bool CreateUDPClient(IYUDPClient** ppIUDPClient);
|
|
|
|
/**
|
|
* 初始化服务
|
|
* @brief Init
|
|
* @return
|
|
*/
|
|
virtual int Init(const bool bBoard) = 0;
|
|
|
|
/**
|
|
* 开始接收UDP数据
|
|
* @brief StartUDPClient
|
|
* @return
|
|
*/
|
|
virtual int StartUDPClient(UdpClientRecvDataFunc pRecvDataFunc) = 0;
|
|
|
|
/**
|
|
* 结束接收UDP数据
|
|
* @brief StopUDPClient
|
|
* @return
|
|
*/
|
|
virtual int StopUDPClient() = 0;
|
|
|
|
/**
|
|
* 发送数据
|
|
* @brief SendData
|
|
* @param pData
|
|
* @param nLen
|
|
* @return
|
|
*/
|
|
virtual int SendData(const int nPort, const char* pAddr, const char* pData, const int nLen) = 0;
|
|
|
|
};
|