text: #pragma once
  
  #include <sys/socket.h>
  #include <netinet/in.h>
  #include <arpa/inet.h>
  #include <unistd.h>
  
  #include <stdexcept>
  #include <iostream>
  #include <vector>
  #include <cstdint>
  #include <string>
  
  template<typename T>
  class Udp
  {
    private:
      int fd{-1};
      sockaddr_in dest;
  
    public:
      Udp(uint16_t port)
      {
        dest.sin_family = AF_INET;
        dest.sin_addr.s_addr = inet_addr("127.0.0.1");
        dest.sin_port = htons(port);
  
        fd = socket(AF_INET, SOCK_DGRAM, 0);
        if (fd < 0) {
          throw std::runtime_error("Unable to open UDP socket on port " + std::to_string(port));
        }
        std::cout << "UDP stream on port " << std::to_string(port) << std::endl;
      }
  
      ~Udp()
      {
        if (fd >= 0) {
          close(fd);
        }
      }
  
      void send(const std::vector<T>& data)
      {
        if (fd >= 0) {
          sendto(fd, (const char*)data.data(), data.size() * sizeof(T), 0, (sockaddr*)&dest, sizeof(dest));
        }
      }
  };
  