larra/examples/src/connect.cpp

28 lines
868 B
C++
Raw Normal View History

2024-09-26 18:11:30 +00:00
#include <spdlog/spdlog.h>
2024-09-03 15:36:08 +00:00
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <larra/client/client.hpp>
#include <larra/printer_stream.hpp>
#include <print>
auto Coroutine() -> boost::asio::awaitable<void> {
2024-09-26 18:11:30 +00:00
SPDLOG_INFO("Connecting client...");
2024-09-03 15:36:08 +00:00
try {
auto client = co_await larra::xmpp::client::CreateClient<larra::xmpp::PrintStream<boost::asio::ip::tcp::socket>>(
2024-09-26 18:11:30 +00:00
larra::xmpp::EncryptionUserAccount{{"test1", "localhost"}, "test1"}, {.useTls = larra::xmpp::client::Options::kNever});
2024-09-03 15:36:08 +00:00
} catch(const std::exception& err) {
2024-09-26 18:11:30 +00:00
SPDLOG_ERROR("{}", err.what());
2024-09-03 15:36:08 +00:00
co_return;
}
2024-09-26 18:11:30 +00:00
SPDLOG_INFO("Done connecting client!");
2024-09-03 15:36:08 +00:00
}
auto main() -> int {
2024-09-26 18:11:30 +00:00
spdlog::set_level(spdlog::level::trace);
2024-09-03 15:36:08 +00:00
boost::asio::io_context io_context;
boost::asio::co_spawn(io_context, Coroutine(), boost::asio::detached);
io_context.run();
}