#pragma once #include #include namespace inaf::oasbo::Receivers { class UDPProtocol: public BaseReceiver { protected: UDPProtocol(std::string ip, int prt); UDPProtocol(); int srv_sock; std::string ip { }; int port; struct sockaddr_in cliaddr; struct sockaddr_in srvaddr; bool split_ip_port(const std::string &ip_port, std::string &ip, int &port); int receiveAtLeastHeaderSizeBytes(uint8_t *buff, int headerSize, int packetSize); void resetPacket(PacketLib::BasePacket&, int bytes); public: ~UDPProtocol(); std::string getHost() override; void setHost(std::string host) override; void setIp(std::string); std::string getIp(){return this->ip;} void setPort(int); int getPort(){return this->port;} int connectToClient() override; int closeConnectionToClient() override; bool isConnectedToClient() const override; int receiveFromClient(PacketLib::BasePacket&) override; friend class UDPProtocolBuilder; }; class UDPProtocolBuilder { protected: UDPProtocol *protocol; public: std::string config_target {"udpreceiver"}; std::string ip_key { "ip" }; std::string port_key { "port" }; UDPProtocolBuilder(); UDPProtocolBuilder(std::string ip, int port); ~UDPProtocolBuilder(); void reset(); UDPProtocolBuilder* configFrom(Configurators::BaseConfigurator &conf); UDPProtocolBuilder* setIp(std::string ip); UDPProtocolBuilder* setPort(int port); UDPProtocol* getReceiver(); }; }