PDA

View Full Version : UDP Listener



ricarlc
10th January 2014, 18:32
I am working with a piece of custom hardware (black box) that is sending UDP packets of data. Looking at the packets in Wireshark I can see that the hardware has the source IP set to 192.168.1.128 on port 4096 and the destination IP set to 0.0.0.0 on port 8192.

I am running a small Qt application on a Windows 7 machine that opens a UDP listener on port 8192 and should display packet data when it is received but, it never receives a packet. At this point I don't care what the data looks like I just want to verfiy that I can receive UDP from the external hardware.

Is this an operating system issue such that Windows will not receive a packet with destination set to 0.0.0.0? Should I use winpcap lib?

Any insight is most appreciated.

I have included an example of the UDP listener code.



Gui::Gui(QWidget *parent)
: QMainWindow(parent){
ui.setupUi(this);

udpSocket = new QUdpSocket(this);

connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));

udpSocket->bind(8192);

setWindowTitle(tr("Display"));
}

void SeekerGui::processPendingDatagrams()
{
while (udpSocket->hasPendingDatagrams())
{
QByteArray datagram;

datagram.resize(udpSocket->pendingDatagramSize());

udpSocket->readDatagram(datagram.data(), datagram.size());

ui.lineEdit_test->setText(tr("Received datagram: \"%1\"").arg(datagram.data()));
}
}

ChrisW67
10th January 2014, 20:35
Have you ensured the Windows (or other) firewall is not blocking the incoming packet or your application as a whole?
Have you tried specifying the interface to bind() to on the receiver?

ricarlc
10th January 2014, 21:49
I made sure that the firewall was disabled during testing.

I'm not sure what you mean by, specifying the interface to bind to.

boudie
11th January 2014, 15:39
You connected the SIGNAL to this.processPendingDatagrams(), while you're showing processPendingDatagrams() as a method in class SeekerGui?

ChrisW67
12th January 2014, 06:34
Indeed, missed that too.

ricarlc
13th January 2014, 16:31
Sorry. SeekerGui should read Gui. The processPendingDatagrams() method resides in the Gui class. My apologies.

Here is the code snippet the way it should read.



Gui::Gui(QWidget *parent) : QMainWindow(parent)
{
ui.setupUi(this);

udpSocket = new QUdpSocket(this);

connect(udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingDatagrams()));

udpSocket->bind(8192);

setWindowTitle(tr("Display"));

}

void Gui::processPendingDatagrams()
{
while (udpSocket->hasPendingDatagrams())
{
QByteArray datagram;

datagram.resize(udpSocket->pendingDatagramSize());

udpSocket->readDatagram(datagram.data(), datagram.size());

ui.lineEdit_test->setText(tr("Received datagram: \"%1\"").arg(datagram.data()));
}
}

ChrisW67
13th January 2014, 20:14
Does the connect call return true?
Is the code in processPendingDatagrams() ever called?

There is a bind() variant that takes two arguments (see the example in the QUdpSocket). The first argument specifies which interface the socket is created on. Have you tried that with the external interface address specified explicitly?