Browse Source

Adapting to ConsoleEmulator port and final results of Console

master
Hatef 2 years ago
parent
commit
e6d63e3008
  1. 13
      main.cpp
  2. 4
      socket.cpp
  3. 2
      socket.h

13
main.cpp

@ -6,17 +6,16 @@ int main(int argc, char* argv[])
{ {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
Logger mylog("thetest8.log"); Logger mylog("Hatef_Console_Log.log");
mylog.clearLog(); mylog.clearLog();
Logger::makeStartingLine(); Logger::makeStartingLine();
UdpSocket server; //UdpSocket server;
UdpSocket client; UdpSocket client(nullptr, 5446);
client.sayHello(); //client.sayHello();
server.sayHello(); //server.sayHello();
client.sayMsg("Msg1C"); //server.sayMsg("Msg1");
server.sayMsg("Msg1S");
return a.exec(); return a.exec();
} }

4
socket.cpp

@ -15,6 +15,7 @@ UdpSocket::UdpSocket(QObject* parent, quint16 port) :
UdpSocket::~UdpSocket() UdpSocket::~UdpSocket()
{ {
qInfo() << "Udp socket deleted!" << "\n"; qInfo() << "Udp socket deleted!" << "\n";
_socket->close();
delete _socket; delete _socket;
} }
@ -34,6 +35,8 @@ void UdpSocket::sayMsg(const QString& msg)
/*******************************************************************************************/ /*******************************************************************************************/
void UdpSocket::readyRead() void UdpSocket::readyRead()
{
while(_socket->hasPendingDatagrams())
{ {
QByteArray buffer; QByteArray buffer;
buffer.resize(_socket->pendingDatagramSize()); buffer.resize(_socket->pendingDatagramSize());
@ -42,3 +45,4 @@ void UdpSocket::readyRead()
_socket->readDatagram(buffer.data(), buffer.size(), &sender_addr, &sender_port); _socket->readDatagram(buffer.data(), buffer.size(), &sender_addr, &sender_port);
Logger::logReceivedData(buffer, sender_addr, sender_port); Logger::logReceivedData(buffer, sender_addr, sender_port);
} }
}

2
socket.h

@ -13,7 +13,7 @@ private:
const quint16 _port; const quint16 _port;
public: public:
explicit UdpSocket(QObject* parent = nullptr, quint16 port = 1234); explicit UdpSocket(QObject* parent = nullptr, quint16 port = 5446);
~UdpSocket(); ~UdpSocket();
void sayHello(); void sayHello();

Loading…
Cancel
Save