feat: add disconnect behaviour

This commit is contained in:
semenov
2024-09-10 17:47:52 +03:00
parent d3e03d6d91
commit e9cd136238
17 changed files with 110 additions and 61 deletions

View File

@@ -31,6 +31,9 @@ void RecognizeSystem::recognize(QTcpSocket *socket)
while(socket->bytesAvailable())
{
if (socket->state() != QTcpSocket::ConnectedState) return;
if(packetType == PacketType::TYPE_NONE){ //определение первичного пакета
stream.startTransaction();

View File

@@ -1,5 +1,5 @@
#include "tcpclient.h"
#include "updatecontroller.h"
#include "UpdateController.h"
#include "externalexecuter.h"
#include <QDir>
@@ -7,7 +7,10 @@
TCPClient::TCPClient(QObject *parent) :
QObject(parent)
{
socket = NULL;
//socket = NULL;
socket = new QTcpSocket();
socket->setParent(this);
socket->moveToThread(this->thread());
}
void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *externalExecuter)
@@ -15,6 +18,7 @@ void TCPClient::initialize(RecognizeSystem *recognize,ExternalExecuter *external
this->recognizeSystem = recognize;
this->externalExecuter = externalExecuter;
emit sigSendDebugLog(Tools::getTime() + " Client started");
}
@@ -26,8 +30,6 @@ void TCPClient::setConnect(ServerSettings *serverSettings)
return;
}
socket = new QTcpSocket(this);
connect(socket,&QTcpSocket::readyRead,this,&TCPClient::slotReadyRead,Qt::DirectConnection);
connect(socket,&QTcpSocket::disconnected,this,&TCPClient::setDisconnect);
connect(socket,&QTcpSocket::connected,this,&TCPClient::slotConnectNotify);
@@ -98,6 +100,7 @@ void TCPClient::sendUnityConnect()
void TCPClient::setDisconnect()
{
socket->disconnect();
emit sigServerDisconnect();
emit sigSendDebugLog("Server disabled");
}

View File

@@ -10,7 +10,7 @@
#include <QCoreApplication>
#include "Core\recognizesystem.h"
#include "Core\tools.h"
#include "Core\updatecontroller.h"
#include "Core\UpdateController.h"
#include "Core\externalexecuter.h"
class UpdateController;
@@ -37,6 +37,7 @@ signals:
void sigSendDebugLog(QString message);
void sigRecognize(QTcpSocket *socket);
void sigConnectionState(bool flag);
void sigServerDisconnect();
QByteArray sigGetXmlAnswer(QString);
public slots: