PDA

View Full Version : QUdpSocket Variable Speed Issue



MrCodeycode
25th February 2014, 10:09
Hi,

I am using QUdpSocket to stream an image locally, and I have noticed after a few hours that the write speed seems to fluctuate, as illustrated in the attached pic.

My program is basically:

connect sendimage() to slot_sendimage()

in a Qthread run loop:
@35Hz, emit sendImage();

Slot definition
slot_sendimage()
{
// say about 30 datagrams per image
for(int a = 0; a < 30; a++)
{
// 4 byte packet header
QByteArray UdpHeader(headerdata,sizeof(headerdata));

// 8188 byte packet data
UdpHeader,append(packetdata);

UdpSocket->writeDatagram(UdpHeader.data(), UdpHeader.size(), QHostAddress(HOST), PORT);
}
// Get the rate at which slot_sendimage() is executed and plot
}

As I said, everything is fine for about 2 hours, then the writeDatagram rate starts to jump around. I am unsure is this a signal->slot issue, a QByteArray.append issue, a QUdpSocket issue, or some ubuntu network management issue.

Any help or input would be much appreciated.

sulliwk06
25th February 2014, 13:17
You could test if its the signal/slot connection (or the timer) by setting it up to not send packets, just update some log and seeing if it still happens.

You could check if its the QByteArray.append by hard coding the packet and sending the same one over and over to see if it still happens.

As for the QUdpSocket or network management issues, I think it would be hard to pinpoint something specific there.

Also, there is no attached pic.

MrCodeycode
5th March 2014, 04:45
Hi, thanks for the suggestions. Turns out the problem was with the signal->slot. I resolved it by using a direct connection from my signal in QThread::run() to the QUdpSocket->write slot function and ignoring the runtime warning of "QObject cannot create child process etc.etc.".

I don't really understand why signal->slot frequency became unreliable after a few hours (queuing related I would assume), nor do I understand the significance of the QObject warning, as it seems to have no affect whatsoever on my application, and now QUdpSocket is writing smoothly at constant speed for over 26 hours.