[Interest] Simple device discovery using UDP

Jason H jhihn at gmx.com
Tue Oct 2 15:44:48 CEST 2018


Forgot to include my sending code, incase that's the problem:

void HostInfoService::update() {
	QNetworkDatagram datagram(QHostInfo::localHostName().toLocal8Bit(), QHostAddress::Broadcast, 13999);
	udpSocket4.writeDatagram(datagram);
	//udpSocket6.writeDatagram(datagram);
	qDebug() << Q_FUNC_INFO << QHostInfo::localHostName().toLocal8Bit();
}

> Sent: Tuesday, October 02, 2018 at 9:43 AM
> From: "Jason H" <jhihn at gmx.com>
> To: "interestqt-project.org" <interest at qt-project.org>
> Subject: [Interest] Simple device discovery using UDP
>
> 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?
> 
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
> 



More information about the Interest mailing list