Older/Server/UdpServer.h

37 lines
972 B
C
Raw Permalink Normal View History

2023-07-21 16:17:01 +08:00
#ifndef UDPSERVER_H
#define UDPSERVER_H
2024-10-01 00:12:57 +08:00
#include <boost/asio.hpp>
2023-07-21 16:17:01 +08:00
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