Im trying to compare the data in the received datagram to a string, when i run the program i see that i receive "test", but the if statement doesnt work.
#include <QUdpSocket>
#include <QTextStream>
#include <string>
#include <QString>
#include <iostream>
int main()
{
QTextStream qout(stdout);
QUdpSocket *udpSocket = new QUdpSocket(0);
udpSocket->bind(3838, QUdpSocket::ShareAddress);
while (udpSocket->waitForReadyRead(-1)) {
while(udpSocket->hasPendingDatagrams()) {
QByteArray datagram;
datagram.resize(udpSocket->pendingDatagramSize());
QHostAddress sender;
quint16 senderPort;
udpSocket->readDatagram(datagram.data(), datagram.size(),
&sender, &senderPort);
qout << "received from " << sender.toString() << datagram.data() << endl;
using namespace std;
string jag = datagram.data();
std::string str1 (jag.c_str());
std::string str2 ("test.");
printf("%s", jag.c_str());
if (str1.compare(str2) == 0)
{
printf("test ok");
}
}
}
}
i have tried with different comparing methods, but nothing worked so far.
printf("%s", jag.c_str()); displays also test when i send test with netcat any ideas? thanks :)