Files
MyChat_Client/network/netclient.h
2025-06-10 20:17:39 +08:00

60 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#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