#include "plotter.hpp" #include // htons, inet_addr #include // socket, sendto #include // close namespace tools { Plotter::Plotter(std::string host, uint16_t port) { socket_ = ::socket(AF_INET, SOCK_DGRAM, 0); destination_.sin_family = AF_INET; destination_.sin_port = ::htons(port); destination_.sin_addr.s_addr = ::inet_addr(host.c_str()); } Plotter::~Plotter() { ::close(socket_); } void Plotter::plot(const nlohmann::json & json) { std::lock_guard lock(mutex_); auto data = json.dump(); ::sendto( socket_, data.c_str(), data.length(), 0, reinterpret_cast(&destination_), sizeof(destination_)); } } // namespace tools