On Tuesday 02 October 2018 15:43:39 Jason H wrote:
> I have an app (Desktop) that I want it to know about other running instances
> on the local network. I figured UDP broadcast was a natural choice. I tried
> it, but I never saw anything but my own (local) packets. There's quite a
> few stackoverflow questions, but none used Qt. I'm wondering if it's a
> wifi/router thing?
> 
> The hosts are on the same WiFi SSID and address space:
> 10.31.4.26 host1
> 10.31.4.202 host2
> 
> Both are on my desk.
> HostInfoService::HostInfoService(...) {
> ...
>       udpSocket4.bind(QHostAddress::Any, 13999, QUdpSocket::ShareAddress);
>       connect(&udpSocket4, SIGNAL(readyRead()), this,
> SLOT(readPendingDatagrams())); ...
> }
> 
> void HostInfoService::readPendingDatagrams()
> {
>       for (auto udpSocket: {&udpSocket4 } ) { //, &udpSocket6}) {
>               while (udpSocket->hasPendingDatagrams()) {
>                       QNetworkDatagram datagram = 
> udpSocket->receiveDatagram();
>                       QString host = QString(datagram.data().constData());
>                       messages[host] = datagram.senderAddress();
>                       qDebug() << Q_FUNC_INFO << host << 
datagram.senderAddress().toString();
>               }
>       }
> }
> 
> I also tried on an IPv6 socket, no joy.
> 
> Has anyone else done something like this?

I recently did this, using Qt. Worked with a problem, but on a wired 
connection.

BCastServer::BCastServer(QObject *parent)
        : QObject(parent)
{
        m_listeningSocket = new QUdpSocket(this);
        m_listeningSocket->bind(45454, QUdpSocket::ShareAddress);
        connect(m_listeningSocket, &QUdpSocket::readyRead, this, 
&BCastServer::processPendingDatagrams);
}

-- 
Best Regards

Reinhardt Behm


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to