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.
86 lines
2.0 KiB
C++
86 lines
2.0 KiB
C++
#ifndef __LIBTCP_H__
|
|
#define __LIBTCP_H__
|
|
|
|
#include <QJsonDocument>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QTextStream>
|
|
#include <QQueue>
|
|
#include <QByteArray>
|
|
#include <QMap>
|
|
#include <QDateTime>
|
|
#include <QSharedPointer>
|
|
#include <QTcpSocket>
|
|
#include <QSslSocket>
|
|
#include <QSsl>
|
|
#include <QSslCertificate>
|
|
#include <QSslKey>
|
|
|
|
typedef struct tagTP_TCP_CLIENT_PARAM{
|
|
QString user_; // 用户名
|
|
QString host_ip_; // 服务器地址
|
|
quint16 port_{6677}; // 服务器端口
|
|
bool enable_ssl_{false}; // 是否启用SSL
|
|
bool auto_reconnect_{false}; // 是否自动重连
|
|
}TP_TCP_CLIENT_PARAM;
|
|
|
|
typedef struct tagTP_TCP_SERVER_PARAM{
|
|
QString host_ip_; // 监听地址, *为所有可用地址
|
|
quint16 port_{6677}; // 监听端口
|
|
bool enable_ssl_{false}; // 是否启用SSL
|
|
QList<QString> user_list_; // 允许的用户列表。空代表无用户验证
|
|
}TP_TCP_SERVER_PARAM;
|
|
|
|
typedef enum TpServerStatus
|
|
{
|
|
ON_RUNNING = 0,
|
|
ON_SHUTDOWN = 1,
|
|
}TpServerStatus;
|
|
|
|
typedef struct tagTP_CLIENT_STATUS
|
|
{
|
|
QString client_name_;
|
|
QString client_ip_;
|
|
QString host_ip_;
|
|
QAbstractSocket::SocketState status;
|
|
int session_id_;
|
|
QDateTime last_active_time_;
|
|
}TP_CLIENT_STATUS;
|
|
typedef QMap<QString, TP_CLIENT_STATUS> ClientsStatusMap;
|
|
|
|
|
|
typedef enum TpProtoParserStatus
|
|
{
|
|
ON_PARSER_INIT = 0,
|
|
ON_PARSER_HAED = 1,
|
|
ON_PARSER_BODY = 2,
|
|
}TpProtoParserStatus;
|
|
|
|
|
|
typedef struct tagTP_PROTOCOL_HEAD
|
|
{
|
|
quint8 version_;
|
|
quint8 magic_;
|
|
quint16 server_;
|
|
quint32 length_;
|
|
}TP_PROTOCOL_HEAD;
|
|
|
|
class TP_PROTOCOL_MESSAGE
|
|
{
|
|
public:
|
|
TP_PROTOCOL_MESSAGE(){}
|
|
~TP_PROTOCOL_MESSAGE(){}
|
|
|
|
public:
|
|
TP_PROTOCOL_HEAD head;
|
|
QJsonObject body;
|
|
};
|
|
|
|
Q_DECLARE_METATYPE(QSharedPointer<TP_PROTOCOL_MESSAGE>)
|
|
#ifndef LPQSHAREDPOINTERQBYTEARRAY
|
|
#define LPQSHAREDPOINTERQBYTEARRAY
|
|
Q_DECLARE_METATYPE(QSharedPointer<QByteArray>)
|
|
#endif
|
|
Q_DECLARE_METATYPE(QSharedPointer<QJsonObject>)
|
|
#endif //__TP_PROTOCOL_H__
|