UDP Server is started
This commit is contained in:
parent
3aace88c0b
commit
488a8ed5dd
@ -6,6 +6,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
, ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->server = new UdpLedServer ();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user