Older/Server/UdpServer.h
2023-07-21 16:17:01 +08:00

37 lines
972 B
C++

#ifndef UDPSERVER_H
#define UDPSERVER_H
#include "boost/asio.hpp"
class UdpServer {
public:
UdpServer(boost::asio::io_context &io_context);
protected:
/**
* @brief reveiveHandler
* @param error Result of operation.
* @param bytes_transferred Number of bytes received.
*/
void reveiveHandler(const boost::system::error_code &error, std::size_t bytes_transferred);
/**
* @brief sendHandler
* @param error Result of operation.
* @param bytes_transferred Number of bytes sent.
*/
void sendHandler(const boost::system::error_code &error, std::size_t bytes_transferred);
void handleReceivedBuffer(std::vector<char> &data);
void sendData();
private:
boost::asio::ip::udp::socket m_socket;
boost::asio::ip::udp::endpoint m_remotePoint; //客户端端点
std::vector<char> m_reveiveBuffer;
boost::asio::steady_timer m_timer;
};
#endif // UDPSERVER_H