[Interest] Simple UDP listener question

Robert Wood robert.wood at apostrophe.co.uk
Mon Jun 23 19:41:31 CEST 2014


Thanks for the suggestions, but no joy with anything still. Not getting 
any errors, let alone receiving any packets.

I'm wondering whether I have fundamentally misunderstood something about 
what I am doing. Or trying to do.

The QHostAddress("192.168.0.18") should be the IP address of my computer 
shouldn't it? I'm not really clear why this is necessary as I would 
assume Qt would automatically pick that up? Or is it in case you  have 
more than one NIC and you are telling the program which one to listen 
on/send from?

Is it necessary to have a second socket for reading or can you read from 
and write to the same socket? I can't see anything on the broadcast 
receive example that specifically says only read or that it is to be 
set-up as a read socket, not write.

I assume that for the method I have tried below it should be OK if the 
packet my embedded device sends out is a unicast packet. ie It can be 
send from 192.168.0.177 (the STM32) to 192.168.0.18 (my computer) and 
the STM32 does not have to send out to 192.168.0.255 for the code I've 
taken from the example?

Can't think of anything else to ask at the moment, hopefully one of 
these questions will make obvious what the issue is!

Thanks again.




On 23/06/14 17:12, Tom Isaacson wrote:
> 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