Skip to content

Commit

Permalink
UDP multicast listen on all appicable interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
agoessling committed Aug 18, 2023
1 parent 92622c5 commit a4d8ab9
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion plotjuggler_plugins/DataStreamUDP/udp_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ THE SOFTWARE.
#include <QMessageBox>
#include <chrono>
#include <QNetworkDatagram>
#include <QNetworkInterface>

#include "ui_udp_server.h"

Expand Down Expand Up @@ -158,7 +159,18 @@ bool UDP_Server::start(QStringList*)
{
success &= _udp_socket->bind(
address, port, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);
success &= _udp_socket->joinMulticastGroup(address);

// Add multicast group membership to all interfaces which support multicast.
for (const auto& interface : QNetworkInterface::allInterfaces())
{
QNetworkInterface::InterfaceFlags iflags = interface.flags();
if (interface.isValid() && !iflags.testFlag(QNetworkInterface::IsLoopBack) &&
iflags.testFlag(QNetworkInterface::CanMulticast) &&
iflags.testFlag(QNetworkInterface::IsRunning))
{
success &= _udp_socket->joinMulticastGroup(address, interface);
}
}
}

_running = true;
Expand Down

0 comments on commit a4d8ab9

Please sign in to comment.