diff --git a/core/src/utils/net.cpp b/core/src/utils/net.cpp index 4df9d9ff..99ff8390 100644 --- a/core/src/utils/net.cpp +++ b/core/src/utils/net.cpp @@ -390,7 +390,7 @@ namespace net { #endif if (setsockopt(s, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(int)) < 0) { closeSocket(s); - throw std::runtime_error("Could not configure socket"); + throw std::runtime_error("Could not enable broadcast on socket"); return NULL; } diff --git a/source_modules/hermes_source/src/hermes.cpp b/source_modules/hermes_source/src/hermes.cpp index 6b02a762..68ad7827 100644 --- a/source_modules/hermes_source/src/hermes.cpp +++ b/source_modules/hermes_source/src/hermes.cpp @@ -205,8 +205,8 @@ namespace hermes { } std::vector discover() { - // TODO: Maybe try to instead detect on each interface as a work around for 0.0.0.0 not receiving anything? - auto sock = net::openudp("0.0.0.0", 1024); + // Open a UDP broadcast socket (TODO: Figure out why 255.255.255.255 doesn't work on windows with local = 0.0.0.0) + auto sock = net::openudp("255.255.255.255", 1024, "0.0.0.0", 0, true); // Build discovery packet uint8_t discoveryPkt[64]; @@ -225,6 +225,7 @@ namespace hermes { } } + // Await all responses std::vector devices; while (true) { // Wait for a response @@ -258,7 +259,9 @@ namespace hermes { devices.push_back(info); } - + + // Close broadcast socket + sock->close(); return devices; }