why is data not transmitted over udp?
-
I'm sending a message by UDP (-9.58924 2) and this is what I get ( "" ) :
0 1 str_priem: "" -9.58924 2 str_priem: "" -5.44021 3 str_priem: "" 6.50288 4 str_priem: "" 9.12945 5 str_priem: "" -1.32352 6 str_priem: "" -9.88032 7 str_priem: ""
here is the code :
one sends the other receives
// тут отправляем сообщение void MainWindow::onTimeoutStart() { str_ip = ui->lE_enover_id->text(); str_port = ui->lE_enover_port->text(); int_port = str_port.toInt(); // превращаем в инты // сообщение // состоит из двух чисел первое Х второе У if(grad >=360 ) { grad = 0; } data_x = 10 * sin(grad); grad = grad + 5; if(data_y >= 100) data_y = 0; data_y = data_y + 1; //отправка QByteArray baDatagram_out; QDataStream out(&baDatagram_out, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_5_3); qDebug() << data_x << " " << data_y; out << data_x; out << data_y; if(ui->lE_enover_id->text().isEmpty() == true) { m_pudp->writeDatagram(baDatagram_out, QHostAddress::LocalHost, int_port); } else { m_pudp->writeDatagram(baDatagram_out, QHostAddress(str_ip), int_port); } }
receive :
void MainWindow::slotProcessDatagrams() { QByteArray baDatagram_in; do { baDatagram_in.resize(m_pudp_in->pendingDatagramSize()); m_pudp_in->readDatagram(baDatagram_in.data(), baDatagram_in.size()); } while(m_pudp_in->hasPendingDatagrams()); QDataStream in(&baDatagram_in, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_5_3); QString str_priem; in >> str_priem; qDebug() << "str_priem: " << str_priem; str_priem.clear(); }
why does only an empty message arrive without "filling"??
-
@timob256 said in why is data not transmitted over udp?:
Thank you for the offer. But alas, I do not know what to write to make it work.
When you put two numbers into a QDataStream you should also read two numbers and not a string - this has nothing to do with programming - when you put two apples into a bag you can't get an banana out of it...
-
@timob256 you write two doubles but read a QString - how should this work?
-
@Christian-Ehrlicher said in why is data not transmitted over udp?:
you write two doubles but read a QString - how should this work?
Thank you for the offer. But alas, I do not know what to write to make it work.
I am not a mathematician and have no education, please tell me what to write.
The 3rd grade of junior high school is all I've finished ;_; . -
@timob256 said in why is data not transmitted over udp?:
Thank you for the offer. But alas, I do not know what to write to make it work.
When you put two numbers into a QDataStream you should also read two numbers and not a string - this has nothing to do with programming - when you put two apples into a bag you can't get an banana out of it...
-