#include #include "client.hpp" #include "protocol.hpp" #include "server.hpp" #include "spdlog/spdlog.h" void init_spdlog() { spdlog::set_level(spdlog::level::debug); // Set global log level to debug // spdlog::set_pattern("[%H:%M:%S %z] [%n] [%^---%L---%$] [thread %t] %v"); spdlog::debug("Setting Loglevel to debug..."); } void run_client() { boost::asio::io_context io_context; spdlog::info("Running client..."); commons::client s(io_context, boost::asio::ip::make_address("0.0.0.0"), 9000, 0); for (int i = 0; i < 100; ++i) { auto msg = std::make_shared(); msg->color = commons::protocol::vec3{i, i, i}; // used as lifetime expansion so that msg doesnt go out of scope till it // actually was sent s.send(msg->serialize(), std::bind(&commons::protocol::generic_message_base::handle_sent, msg, std::placeholders::_1)); } io_context.run(); } void run_server() { boost::asio::io_context io_context; spdlog::info("Running server..."); commons::server s(io_context, 9000); io_context.run(); } int main(int argc, char *argv[]) { init_spdlog(); try { if (argc == 1) { run_client(); } if (argc == 2) { run_server(); } } catch (std::exception &e) { std::cerr << "Exception: " << e.what() << "\n"; } return 0; }