LED-BOARD/simulation/VirtualLedBoard/udpserver.cpp
2023-08-14 13:53:34 +02:00

36 lines
852 B
C++

#include "udpserver.h"
#include <QUdpSocket>
#include <QNetworkDatagram>
#define UDP_IMAGE_PORT 4242
UdpLedServer ::UdpLedServer (QObject *parent)
: QObject(parent)
{
initSocket();
}
void UdpLedServer ::initSocket()
{
this->mUdpSocket = new QUdpSocket(this);
this->mUdpSocket->bind(QHostAddress::LocalHost, UDP_IMAGE_PORT);
connect(this->mUdpSocket, &QUdpSocket::readyRead,
this, &UdpLedServer ::readPendingDatagrams);
}
void UdpLedServer ::readPendingDatagrams()
{
while (this->mUdpSocket->hasPendingDatagrams()) {
QNetworkDatagram datagram = this->mUdpSocket->receiveDatagram();
processTheDatagram(datagram);
}
}
void UdpLedServer::processTheDatagram(QNetworkDatagram datagram) {
if (datagram.isValid()) {
qDebug() << "Received datagram:" << datagram.data().size();
}
}