feat: send xml answer

This commit is contained in:
semenov
2024-08-15 15:30:22 +03:00
parent 7ba182b6cf
commit 883ac44e6b
41 changed files with 1499 additions and 876 deletions

View File

@@ -1,5 +1,5 @@
#include "tcpclient.h"
#include "UpdateController.h"
#include "Core/updatecontroller.h"
#include "externalexecuter.h"
#include <QDir>
@@ -7,9 +7,7 @@
TCPClient::TCPClient(QObject *parent) :
QObject(parent)
{
socket = new QTcpSocket(this);
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::onReadyRead);
}
void TCPClient::Initialize(UpdateController *updateController,
@@ -20,22 +18,48 @@ void TCPClient::Initialize(UpdateController *updateController,
this->recognizeSystem = recognize;
this->externalExecuter = externalExecuter;
recognize->SetSocket(socket);
emit onSendDebugLog(Tools::GetTime() + " Client started");
}
void TCPClient::SetConnect(ServerSettings *serverSettings)
{
socket = new QTcpSocket(this);
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::onReadyRead);
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::SetDisconnect);
socket->connectToHost(serverSettings->Address,serverSettings->Port.toShort());
emit onSendDebugLog("Try connect...");
recognizeSystem->SetSocket(socket);
socket->waitForReadyRead();
if(socket->state() != QTcpSocket::ConnectedState){
emit onSendDebugLog("Connect invalid");
return;
}else{
emit onSendDebugLog("Connect complete");
}
}
void TCPClient::SendClientAutorization()
{
QDataStream stream(socket);
stream.setVersion(QDataStream::Qt_DefaultCompiledVersion);
QFile file(tempName);
file.open(QIODevice::ReadOnly);
QByteArray array = file.readAll();
stream << PacketType::TYPE_XMLANSWER;
stream << array;
socket->waitForBytesWritten();
}
void TCPClient::SetDisconnect()
{
socket->disconnect();
emit onSendDebugLog("Server disabled");
}
void TCPClient::WaitWrites()
@@ -48,12 +72,7 @@ QTcpSocket *TCPClient::GetSocket()
return socket;
}
TCPClient::~TCPClient()
{
}
void TCPClient::onMessageEntered(QString message)
void TCPClient::MessageEntered(QString message)
{
QDataStream stream(socket);
QByteArray data;
@@ -94,7 +113,11 @@ void TCPClient::onReadyRead()
emit onSendDebugLog("WRONG SOCKET");
return;
}
//возврат на случай недоступного сокета
recognizeSystem->Recognize();
}
TCPClient::~TCPClient()
{
}