2018-05-26 14:49:18 +08:00
|
|
|
|
#ifndef CEDIANUDPPROTOCOL_H
|
2018-01-27 22:14:00 +08:00
|
|
|
|
#define CEDIANUDPPROTOCOL_H
|
|
|
|
|
|
2018-05-26 14:49:18 +08:00
|
|
|
|
#include <qqtprotocol.h>
|
2018-01-27 22:14:00 +08:00
|
|
|
|
#include <cedianudpmessage.h>
|
|
|
|
|
#include <qqtcore.h>
|
|
|
|
|
#include <cedianudpserver.h>
|
|
|
|
|
|
2018-05-26 14:49:18 +08:00
|
|
|
|
class CedianUdpProtocol : public QQtProtocol
|
2018-01-27 22:14:00 +08:00
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2018-05-26 14:49:18 +08:00
|
|
|
|
explicit CedianUdpProtocol ( QObject* parent = nullptr );
|
2018-01-27 22:14:00 +08:00
|
|
|
|
virtual ~CedianUdpProtocol() {}
|
|
|
|
|
|
|
|
|
|
QNetworkDatagram& dataGram() { return mDG; }
|
|
|
|
|
QHostAddress& address() { return mAddress; }
|
|
|
|
|
qint32& port() { return mPort; }
|
|
|
|
|
qint32& localPort() { return mLocalPort; }
|
|
|
|
|
CedianUdpMessage& msg() { return mMsg; }
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void msgIncoming();
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
|
|
// QQtUdpProtocol interface
|
|
|
|
|
protected:
|
2018-05-26 14:49:18 +08:00
|
|
|
|
virtual bool dispatcher ( const QByteArray& ) override;
|
2018-01-27 22:14:00 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
/*发送者IP 端口 这个IP比较重要,但是在程序中没有用*/
|
|
|
|
|
QHostAddress mAddress;
|
|
|
|
|
qint32 mPort;
|
|
|
|
|
/*这个端口是重点*/
|
|
|
|
|
qint32 mLocalPort;
|
|
|
|
|
CedianUdpMessage mMsg;
|
|
|
|
|
QNetworkDatagram mDG;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*建议空调用一次,赋值parent,进行初始化*/
|
2018-05-26 14:49:18 +08:00
|
|
|
|
CedianUdpProtocol* cedianUdpServer ( QObject* parent = 0 );
|
|
|
|
|
qint32 cedianUdpPort ( int siteID, qint32* portList = 0 );
|
2018-01-27 22:14:00 +08:00
|
|
|
|
|
|
|
|
|
#endif // CEDIANUDPPROTOCOL_H
|