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(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
this->server = new UdpLedServer ();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include "udpserver.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
@ -17,5 +18,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
UdpLedServer *server;
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
@ -4,23 +4,23 @@
|
|||||||
|
|
||||||
#define UDP_IMAGE_PORT 4242
|
#define UDP_IMAGE_PORT 4242
|
||||||
|
|
||||||
UdpServer::UdpServer(QObject *parent)
|
UdpLedServer ::UdpLedServer (QObject *parent)
|
||||||
: QAbstractItemModel(parent)
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
initSocket();
|
initSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UdpServer::initSocket()
|
void UdpLedServer ::initSocket()
|
||||||
{
|
{
|
||||||
this->mUdpSocket = new QUdpSocket(this);
|
this->mUdpSocket = new QUdpSocket(this);
|
||||||
this->mUdpSocket->bind(QHostAddress::LocalHost, UDP_IMAGE_PORT);
|
this->mUdpSocket->bind(QHostAddress::LocalHost, UDP_IMAGE_PORT);
|
||||||
|
|
||||||
connect(this->mUdpSocket, &QUdpSocket::readyRead,
|
connect(this->mUdpSocket, &QUdpSocket::readyRead,
|
||||||
this, &UdpServer::readPendingDatagrams);
|
this, &UdpLedServer ::readPendingDatagrams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void UdpServer::readPendingDatagrams()
|
void UdpLedServer ::readPendingDatagrams()
|
||||||
{
|
{
|
||||||
while (this->mUdpSocket->hasPendingDatagrams()) {
|
while (this->mUdpSocket->hasPendingDatagrams()) {
|
||||||
QNetworkDatagram datagram = this->mUdpSocket->receiveDatagram();
|
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()) {
|
if (datagram.isValid()) {
|
||||||
qDebug() << "Received datagram:" << datagram.data().size();
|
qDebug() << "Received datagram:" << datagram.data().size();
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@
|
|||||||
#include <QAbstractItemModel>
|
#include <QAbstractItemModel>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
|
||||||
class UdpServer : public QAbstractItemModel
|
class UdpLedServer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UdpServer(QObject *parent = nullptr);
|
explicit UdpLedServer (QObject *parent = nullptr);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user