Unsolved Can we receive large (1064) udp datagram
-
Hi
I want to use Qt UDP (not TCP) socket to recieve.I tried to recieve small packets like 15 bytes in qt .Small packets are recieving properly but while i tried to recieve 1064 packets data QT is not recieving properly ,However i can recieve full data in wireshark .
Here is my normal codeMainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
socket = new QUdpSocket(this);
socket->bind(QHostAddress("192.168.10.1"),64826));
connect(socket,SLOT(readyread(),this,SLOT(readdata());
}
void MainWindow::readdata()
{
QHostAddress sender;
quint16 port;
QByteArray buffer;
QByteArray Data;
buffer.resize(socket1->pendingDatagramSize());
socket1->readDatagram(buffer.data(),buffer.size(),&sender,&senderport);
qDebug()<<"sender"<<sender;
qDebug()<<"data"<<buffer;
}Can anyone help me ,Thanks.
-
@Sowjanya In what way it does not work for big packets?
-
@jsulm through fpga i tried to recieve packets
-
@Sowjanya said in Can we recieve large(1064) udp datagram:
i tried to recieve packets
And what happened?
What exactly did not work?
Can you be more precise? -
@jsulm i sent data to fpga through that i recieved some thousands of packets ,which are in 1064(lenth) .In wireshark i can able to see ,but in qt only some packets are recieving
ex:12mb data
i am getting 1mb data -
@Sowjanya well it's udp so there is no guarantee that your datagram comes in one go (especially filtered through the OS and Qt interface)
You have to impose some kind of protocol on it, so that you know this chunk of bytes is one coherent datagram and the next one belongs to an other one.
You need error checking as well, your datagram may loos bytes
-
@Sowjanya Please take a look at the example in https://doc.qt.io/qt-5/qudpsocket.html
In your slot you should read as long as there are still pending datagrams:while (udpSocket->hasPendingDatagrams()) { QNetworkDatagram datagram = udpSocket->receiveDatagram(); processTheDatagram(datagram); }
In your current code you only read one datagram.
-
This post is deleted! -
@jsulm
Hi i again tried like this,but i cant able to recieve properly
{
ui->setupUi(this);
socket = new QUdpSocket(this);
socket->bind(QHostAddress("192.168.10.1"),64826));
connect(socket,SLOT(readyread(),this,SLOT(readdata());
}
void MainWindow::readdata()
{
QHostAddress sender;
quint16 port;
QByteArray buffer;
QByteArray Data;
while (socket->hasPendingDatagrams())
{
QNetworkDatagram datagram = socket->receiveDatagram();
qDebug()<<"data"<<datagram.data();
// processTheDatagram(datagram);
}
} -
@Sowjanya said in Can we receive large (1064) udp datagram:
but i cant able to recieve properly
Code looks about right to me. Please don't say just "but i cant able to recieve properly", you have debug statement there, why not tell people what it did/did not output? Or do you prefer people trying to help should just have to guess for themselves?
-
@Sowjanya said in Can we receive large (1064) udp datagram:
i cant able to recieve properly
In addition to @JonB suggested, you may want to analyze network traffic to/from your Qt app by means of Wireshark to confirm what data is actually flowing back and forth in the connection...