#include #include #include #include #include "api_v1_devices.h" using namespace api::v1; void devices::post_discover(const HttpRequestPtr &req, std::function &&callback) { LOG_DEBUG << "Discovering"; auto resp = HttpResponse::newHttpResponse(); int discovery_server_socket = helpers::bind_tcp_server("0.0.0.0", "0", config::discover_max_client_backlog); int discover_server_port = helpers::get_server_port(discovery_server_socket); if(discover_server_port == -1) { resp->setStatusCode(k500InternalServerError); callback(resp); return; } Json::Value payload; payload["port"] = discover_server_port; Json::StreamWriterBuilder wbuilder; helpers::send_udp_broadcast("255.255.255.255", config::discover_port_dev, Json::writeString(wbuilder, payload).c_str()); close(discovery_server_socket); callback(resp); }