You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
#ifndef NETCONTROL_H
|
|
#define NETCONTROL_H
|
|
|
|
#include <QTcpSocket>
|
|
#include <QHostAddress>
|
|
#include <QTimer>
|
|
#include <QThread>
|
|
|
|
#include <QJsonDocument>
|
|
#include <QJsonArray>
|
|
#include <QJsonObject>
|
|
#include <QJsonParseError>
|
|
#include <QJsonValue>
|
|
#include <QFile>
|
|
|
|
#include "commonDefine.h"
|
|
|
|
class NetControl : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
NetControl(const QString& IpPath, bool bAutoReconnect = false, QObject *parent = 0);
|
|
~NetControl();
|
|
public:
|
|
//void deCodeMsg(QString recInfo);
|
|
Q_SLOT void onInitNet();
|
|
void waitForConnected(int msec);
|
|
Q_SLOT void onSendMsg(const QString& msg);
|
|
|
|
private:
|
|
bool initIpAddress(const QString& path);
|
|
void connectNet(QString severIp, int serverPort);
|
|
|
|
Q_SLOT void sendHeartbeatPack();
|
|
Q_SLOT void onConnected();
|
|
Q_SLOT void onDisconnected();
|
|
Q_SLOT void onErrorHandler(QAbstractSocket::SocketError err);
|
|
Q_SLOT void onMsgReceived();
|
|
private:
|
|
QTcpSocket* m_pTcpSocket;
|
|
qintptr m_socketDescriptor;
|
|
|
|
QString m_szHostIp;
|
|
quint16 m_port;
|
|
QString m_streetName;
|
|
bool m_bAutoReconnect;
|
|
QString m_configPath;
|
|
int m_heartInterval{ 5 };
|
|
|
|
//QThread* m_pThread;
|
|
QTimer* m_pTimerHeartbeat;
|
|
signals:
|
|
void sgReceiveData(const QString& data);
|
|
};
|
|
|
|
|
|
#endif // NETCONTROL_H
|