Small server library using Boost.Asio that can work with any protocol, such as TCP, UDP, Unix Domain Sockets, etc. It abstracts away the boilerplate code, allowing you to focus on implementing your custom receiver logic.
- Define Your Receiver Class: Implement a class inheriting from
receiver
for your specific protocol. Override theoperator()
to handle the socket operations.
#include <aserver.hpp>
#include <boost/asio.hpp>
namespace net = boost::asio;
using namespace aserver;
class TcpReceiver : public receiver<net::ip::tcp> {
public:
void operator()(net::io_context &ioc, net::ip::tcp::socket socket,
stop_signal stop, net::yield_context yield) override
{
// Implement your custom socket handling logic here
}
};
- Set Up the Server: Use the
server
class to start receiving connections on a specified endpoint.
#include <aserver.hpp>
namespace net = boost::asio;
using namespace aserver;
int main()
{
server server;
server.bind_receiver<TcpReceiver>({net::ip::tcp::v4(), 10001});
server.bind_receiver<UdpReceiver>({net::ip::udp::v4(), 10002});
server.run();
return 0;
}
This code is distributed under the MIT License