[Interest] Simple UDP listener question

Tom Isaacson Tom.Isaacson at navico.com
Mon Jun 23 18:12:58 CEST 2014


I have a similar piece of code but the one difference I can see is that when I bind the receive socket I also have QUdpSocket::ReuseAddressHint and I use the same parameters on the send socket. I'm not sure if this will help:

     udpSocSend = new QUdpSocket(this);
     udpSocRec = new QUdpSocket(this);
     udpSocSend->bind(QHostAddress("192.168.0.18"), 6454, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
     udpSocRec->bind(6454, QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint);
     connect(udpSocRec, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));

The other thing you can do is receive any errors from the socket:
    connect(udpSocRec, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(SocketError(QAbstractSocket::SocketError)));

void SocketError(QAbstractSocket::SocketError)
{
    DbgPrintf(dynamic_cast<QUdpSocket *>(sender())->objectName() + QString(": ") + dynamic_cast<QUdpSocket *>(sender())->errorString());
}

Tom Isaacson

-----Original Message-----
From: interest-bounces+tom.isaacson=navico.com at qt-project.org [mailto:interest-bounces+tom.isaacson=navico.com at qt-project.org] On Behalf Of Robert Wood
Sent: Tuesday, 24 June 2014 12:03 a.m.
To: interest at qt-project.org
Subject: [Interest] Simple UDP listener question

Folks,

I've managed to get a simple program going that sends out a UDP packet to a broadcast address (an Artnet Poll packet) and my embedded software is receiving this and sending out a Poll reply. Wireshark confirms that my embedded device is sending out the correct response, however, my Qt program is not picking up any reply at all. I should say, this is the first time I've used Qt for networking and it's my first embedded netowrking project, so I may be missing some very basic point.

I am doing this in MainWindow initialisation:

     udpSocSend = new QUdpSocket(this);
     udpSocRec = new QUdpSocket(this);
     udpSocSend->bind(QHostAddress("192.168.0.18"),6454);
     udpSocRec->bind(6454, QUdpSocket::ShareAddress);
     connect(udpSocRec, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));

void MainWindow::processPendingDatagrams()
{

     while (udpSocRec->hasPendingDatagrams())
         {
         QByteArray datagram;
         datagram.resize(udpSocRec->pendingDatagramSize());
         udpSocRec->readDatagram(datagram.data(), datagram.size());
         ui->textEdit->setText(tr("Received datagram: 
\"%1\"").arg(datagram.data()));

         }
}

My udpSocSend is working to send data out (an Artnet Poll), my STM32 (embedded micro) is sending packets back according to Wireshark, but
processPendingDatagrams() flatly refuses to be called!

Wireshark shows this in terms of a reply:

2475	795.416268000	192.168.0.177	192.168.0.18	ARTNET	282	ArtPollReply 
(0x2100)

The STM32 is at address 192.168.0.177, my [Linux] Qt machine is 192.168.0.18.

The data in the datagram looks OK mto me on Wireshark.

Can anyone see anything I am doing wrong please?

Thanks!

Rob
_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest





More information about the Interest mailing list