Created
September 5, 2014 23:24
-
-
Save thammi/a062aff125ac25150f1c to your computer and use it in GitHub Desktop.
Testing link-local multicast in Qt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##################################################################### | |
# Automatically generated by qmake (3.0) Sa. Sep. 6 01:08:04 2014 | |
###################################################################### | |
CONFIG += console | |
QT += network | |
TEMPLATE = app | |
TARGET = test | |
INCLUDEPATH += . | |
# replace filename or rename ... | |
SOURCES += test.cpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QUdpSocket> | |
#include <QNetworkInterface> | |
#include <QThread> | |
int main(int argc, char *args[]) { | |
// iterates over the interfaces and sends on each | |
while(true) { | |
QUdpSocket udp; | |
QByteArray data("hello world"); | |
foreach(const QHostAddress& address, QNetworkInterface::allAddresses()) { | |
udp.bind(address, 0); | |
qDebug() << address; | |
if(address.protocol() == QAbstractSocket::IPv6Protocol) { | |
udp.writeDatagram(data, QHostAddress("FF02::1"), 4321); | |
} else if(address.protocol() == QAbstractSocket::IPv4Protocol) { | |
udp.writeDatagram(data, QHostAddress::Broadcast, 4321); | |
} | |
udp.close(); | |
} | |
QThread::sleep(5); | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QUdpSocket> | |
#include <QThread> | |
int main(int argc, char *args[]) { | |
// simple test | |
while(true) { | |
QUdpSocket udp; | |
qDebug() << udp.writeDatagram(QByteArray("hello world"), QHostAddress("FF02::1"), 4321); | |
qDebug() << udp.writeDatagram(QByteArray("hello world"), QHostAddress::Broadcast, 4321); | |
QThread::sleep(5); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment