#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);
    void SetExitFlag(bool flag);
    void closeConnect();    // 关闭连接


private:
    QTcpSocket* tcp_ = nullptr;
    QTimer *heartbeatTimer_;
    QString ip_;
    int port_;

    QString carType = "0";
    bool direction = false;
    QString come_time = "";

    bool exit_flag = false;     // 退出标记

public slots:
    void connectToServer(QString ip, int port);

signals:
    void comeTrainSignals(bool type);
    void getDirectionSignals(int direction);
    void sendTcpInfoSignals(QString info);
    void socketComplete(QTcpSocket* tcp, QString ip, quint16 port); // tcp句柄发送给主线程监管
    void restartSocket(QString ip, int port); //重启Socket连接
    void getTcpInfoSignals(QString info);

};
#endif // TCPCLIENT_H
