No, I want the signal for when the remote device responds to my send.
I realize I was making the code unnecessarily complicated; here's my current version:
// create the socket, bind to it and set some options.
m_sock = new QUdpSocket(this);
rc = m_sock->bind(m_addrRecv, MCAST_PORT, QAbstractSocket::ShareAddress | QAbstractSocket::ReuseAddressHint);
if (rc == false)
{
cout << m_sock->errorString().toStdString() << endl;
exit(1);
}
m_sock->setSocketOption(QAbstractSocket::MulticastLoopbackOption, 0);
// join multicast group.
rc = m_sock->joinMulticastGroup(m_addrSend);
if (rc == false)
{
cout << m_sock->errorString().toStdString() << endl;
exit(1);
}
QObject::connect(m_sock, &QUdpSocket::readyRead, this, &UdpSocket::recv);
QObject::connect(m_sock, &QUdpSocket::disconnected, this, &UdpSocket::reconnect);
qnil = QNetworkInterface::allInterfaces();
for (it = qnil.begin(); it != qnil.end(); ++it)
{
type = it->type();
if (type == QNetworkInterface::Ethernet)
{
//m_socketInterfaceMap.insert(m_sock, *it);
qDebug() << it->humanReadableName() << type;
m_sock->setMulticastInterface(*it);
send(str);
}
}
My concern now is that I'm not getting any hit on my recv() slot. Once I get that working, I can work out the matter of determining which interface was used, using the technique you described above. EDIT: I simplified it further, by only writing to the interface I know is correct, and I still don't get a recv() trigger. I think I must have messed up something in my multicast setup.
EDIT 2: I found the problem -- evidently, even if you choose an interface for a socket, when you call joinMulticastGroup, you still have to specify the interface, or the OS will choose one for you. With the change below, I'm now getting my recv() slot.
for (it = qnil.begin(); it != qnil.end(); ++it)
{
type = it->type();
// if (type == QNetworkInterface::Ethernet)
if (it->humanReadableName() == "Ethernet 3")
{
//m_socketInterfaceMap.insert(m_sock, *it);
qDebug() << it->humanReadableName() << type;
m_sock->setMulticastInterface(*it);
// join multicast group.
rc = m_sock->joinMulticastGroup(m_addrSend, *it);
Now I just have to use that stuff that SGaist suggested above to determine which interface supplied the response.