From e6d63e30083694032e60dc82797765948577479f Mon Sep 17 00:00:00 2001 From: Hatef Date: Mon, 11 Jul 2022 12:40:13 +0430 Subject: [PATCH] Adapting to ConsoleEmulator port and final results of Console --- main.cpp | 13 ++++++------- socket.cpp | 16 ++++++++++------ socket.h | 2 +- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/main.cpp b/main.cpp index 0f83e76..4ad837c 100644 --- a/main.cpp +++ b/main.cpp @@ -6,17 +6,16 @@ int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); - Logger mylog("thetest8.log"); + Logger mylog("Hatef_Console_Log.log"); mylog.clearLog(); Logger::makeStartingLine(); - UdpSocket server; - UdpSocket client; +//UdpSocket server; + UdpSocket client(nullptr, 5446); - client.sayHello(); - server.sayHello(); - client.sayMsg("Msg1C"); - server.sayMsg("Msg1S"); +//client.sayHello(); +//server.sayHello(); +//server.sayMsg("Msg1"); return a.exec(); } diff --git a/socket.cpp b/socket.cpp index 776525d..18a79d9 100644 --- a/socket.cpp +++ b/socket.cpp @@ -15,6 +15,7 @@ UdpSocket::UdpSocket(QObject* parent, quint16 port) : UdpSocket::~UdpSocket() { qInfo() << "Udp socket deleted!" << "\n"; + _socket->close(); delete _socket; } @@ -35,10 +36,13 @@ void UdpSocket::sayMsg(const QString& msg) /*******************************************************************************************/ void UdpSocket::readyRead() { - QByteArray buffer; - buffer.resize(_socket->pendingDatagramSize()); - QHostAddress sender_addr; - quint16 sender_port; - _socket->readDatagram(buffer.data(), buffer.size(), &sender_addr, &sender_port); - Logger::logReceivedData(buffer, sender_addr, sender_port); + while(_socket->hasPendingDatagrams()) + { + QByteArray buffer; + buffer.resize(_socket->pendingDatagramSize()); + QHostAddress sender_addr; + quint16 sender_port; + _socket->readDatagram(buffer.data(), buffer.size(), &sender_addr, &sender_port); + Logger::logReceivedData(buffer, sender_addr, sender_port); + } } diff --git a/socket.h b/socket.h index 3bb4da5..1b83fb2 100644 --- a/socket.h +++ b/socket.h @@ -13,7 +13,7 @@ private: const quint16 _port; public: - explicit UdpSocket(QObject* parent = nullptr, quint16 port = 1234); + explicit UdpSocket(QObject* parent = nullptr, quint16 port = 5446); ~UdpSocket(); void sayHello();