mirror of
https://gitee.com/Zhaoxin59/my-chat_-client.git
synced 2026-02-14 00:51:48 +08:00
add http and websocket
This commit is contained in:
59
network/netclient.h
Normal file
59
network/netclient.h
Normal 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
|
||||
Reference in New Issue
Block a user