UDP Server is started

This commit is contained in:
Ollo 2023-08-14 13:53:34 +02:00
parent 3aace88c0b
commit 488a8ed5dd
4 changed files with 11 additions and 8 deletions

View File

@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->server = new UdpLedServer ();
}
MainWindow::~MainWindow()

View File

@ -2,6 +2,7 @@
#define MAINWINDOW_H
#include <QMainWindow>
#include "udpserver.h"
QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
@ -17,5 +18,6 @@ public:
private:
Ui::MainWindow *ui;
UdpLedServer *server;
};
#endif // MAINWINDOW_H

View File

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

View File

@ -4,12 +4,12 @@
#include <QAbstractItemModel>
#include <QUdpSocket>
class UdpServer : public QAbstractItemModel
class UdpLedServer : public QObject
{
Q_OBJECT
public:
explicit UdpServer(QObject *parent = nullptr);
explicit UdpLedServer (QObject *parent = nullptr);
private: