add http and websocket

This commit is contained in:
xyz
2025-06-10 20:17:39 +08:00
parent 030b5d6101
commit 68cd53a80c
23 changed files with 650 additions and 171 deletions

59
network/netclient.h Normal file
View File

@ -0,0 +1,59 @@
#pragma once
#include <QObject>
#include <QNetworkAccessManager>
#include <QWebSocket>
#include <QProtobufSerializer>
#include <qnetworkreply.h>
#include <QUuid>
#include "../model/data.h"
//此处为了避免“循环包含”的问题,就需要使用前置声明的方法
// 代替包含头文件
namespace model {
class DataCenter;
} //end namespace model
class model::DataCenter;
namespace network {
class NetClient : public QObject
{
Q_OBJECT
private:
//定义重要的常量ip暂时使用本地的回环ip端口号暂定的8000和8001
const QString HTTP_URL = "http://127.0.0.1:8000";
const QString WEBSOCKET_URL = "ws://127.0.0.1:8001/ws";
public:
NetClient(model::DataCenter* dataCenter);
//验证网络的联通性
void ping();
//初始化websocket
void initWebSocket();
//发送身份认证请求
void sendAuth();
//生成请求的Id
static QString makeRequestId();
void getMyself(const QString& loginSessionId);
private:
model::DataCenter* dataCenter;
//http客户端
QNetworkAccessManager httpClient;
//websocket客户端
QWebSocket websocketClient;
//序列化器
QProtobufSerializer serializer;
signals:
};
} //end namespace network