The Tablo Udp Discovery module can be used to easely implement UDP discovery into your project.
To use TUD in your project you need to include it first. After including TUD to your project you can implement the server like this:
#include "server_discovery.h"auto serverDiscovery = std::make_shared<tud::ServerDiscovery>(interface, 4000, 4001, "yourNewIdenifier");
std::thread serverDiscoveryThread([serverDiscovery]() {
serverDiscovery->discoveryCycle();
});And the client like this:
#include "client_discovery.h"auto clientDiscovery = std::make_shared<tud::ClientDiscovery>(interface, 4000, 4001, "yourNewIdenifier");
std::thread clientDiscoveryThread([clientDiscovery]() {
clientDiscovery->discoveryCycle();
});Both constructors want:
- your internet interface (string)
- your in port (int)
- your out port (int)
- your identifier (optional string)
Then you can use it with these functions:
std::vector<std::string> getDiscoveredAddresses();
void removeDiscoveredAddress(std::string address);
std::string getLocalIpAddress(std::string interface);
std::string getBroadcastIpAddress();
bool isValidIpV4(std::string &ipString);