32 lines
593 B
C
32 lines
593 B
C
|
|
#ifndef TCPCLIENT_H
|
|||
|
|
#define TCPCLIENT_H
|
|||
|
|
#include <QTcpSocket>
|
|||
|
|
#include <QJsonDocument>
|
|||
|
|
#include <QJsonObject>
|
|||
|
|
#include <QTimer>
|
|||
|
|
#include "common.h"
|
|||
|
|
|
|||
|
|
class TcpClient : public QObject
|
|||
|
|
{
|
|||
|
|
Q_OBJECT
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
explicit TcpClient(QObject *parent = nullptr);
|
|||
|
|
|
|||
|
|
public slots:
|
|||
|
|
void connectToServer(const QString &host, int port);
|
|||
|
|
void onReadyRead();
|
|||
|
|
void sendHeartbeat();
|
|||
|
|
void reconnect();
|
|||
|
|
void handleConnected();
|
|||
|
|
void handleDisconnected();
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
QTcpSocket m_tcpSocket;
|
|||
|
|
QTimer *m_heartbeatTimer;
|
|||
|
|
QString m_host;
|
|||
|
|
int m_port;
|
|||
|
|
|
|||
|
|
};
|
|||
|
|
#endif // TCPCLIENT_H
|