HITDAQ/hit2023v2_RMS/udpserver.h

57 lines
1.3 KiB
C
Raw Permalink Normal View History

#ifndef UDPSERVER_H
#define UDPSERVER_H
#include <QObject>
2024-02-01 18:45:41 +01:00
#include <QVector>
#include <QThread>
#include <QUdpSocket>
2024-02-01 18:45:41 +01:00
class UDPServer : public QObject
{
Q_OBJECT
2024-02-01 18:45:41 +01:00
private:
QUdpSocket* udpSocket; // UDP socket for communication
quint16 serverPort = 12345; // Port number for the UDP server
2024-02-01 18:45:41 +01:00
public:
UDPServer(QObject* parent = nullptr) : QObject(parent)
{
// Initialize and configure your UDP server here
2024-02-01 18:45:41 +01:00
}
2024-02-01 18:45:41 +01:00
public slots:
void startServer()
{
// Start your UDP server here
udpSocket = new QUdpSocket(this);
// Bind the socket to a specific IP address and port
if ( udpSocket->bind(QHostAddress("10.0.7.1"), serverPort) )
{
connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));
qDebug() << "UDP server started on port" << serverPort;
}
else
{
qWarning() << "Failed to bind UDP socket on port" << serverPort;
}
}
void stopServer()
{
// Stop your UDP server here
if (udpSocket)
{
udpSocket->close();
udpSocket->deleteLater();
}
qDebug() << "UDP server stopped";
}
// Add any other methods and signals relevant to your UDP server
};
#endif // UDPSERVER_H