Skip to content

Instantly share code, notes, and snippets.

@iamazeem
Created February 16, 2017 11:43
Show Gist options
  • Save iamazeem/4de7334b084c56f2d5d31a0d36782f87 to your computer and use it in GitHub Desktop.
Save iamazeem/4de7334b084c56f2d5d31a0d36782f87 to your computer and use it in GitHub Desktop.
#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