Created
February 16, 2017 11:43
-
-
Save iamazeem/4de7334b084c56f2d5d31a0d36782f87 to your computer and use it in GitHub Desktop.
This file contains 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 <QCoreApplication> | |
#include <QUdpSocket> | |
#include <QObject> | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
QUdpSocket _s; | |
_s.bind( QHostAddress::LocalHost, 9000 ); | |
QObject::connect( &_s, &QUdpSocket::readyRead, [&_s]() | |
{ | |
QByteArray data {}; | |
while( _s.hasPendingDatagrams() ) | |
{ | |
auto size = _s.pendingDatagramSize(); | |
data.resize( size ); | |
_s.readDatagram( data.data(), size ); | |
data.trimmed(); | |
qDebug() << data << "size:" << size; | |
} | |
}); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment