Skip to content

IvanPinezhaninov/aserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aserver

Language C++11 MIT License Build status

Overview

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.

Usage

  1. Define Your Receiver Class: Implement a class inheriting from receiver for your specific protocol. Override the operator() 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
  }
};
  1. 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;
}

License

This code is distributed under the MIT License

Author

Ivan Pinezhaninov

About

Small server library using Boost.Asio

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published