Why udpsocket does not receive anything?
-
wrote on 1 Mar 2013, 16:53 last edited by
I connect a desktop which has Ubuntu12 installed to a microcontroller board directly by ethernet cable. Microcontoller side does not have any TCP/IP stack and server related function, it can only send out UDP format packet. So when ethernet cable are plugged, desktop computer cannot automatically configured for network. I manually set IP address 10.10.10.11, submask 10.10.10.255, gateway 10.10.10.1, and manually turned it on. with the WireShark's help, I can see the UDP packet coming from microcontrollor and UDP packet sent out by desktop. both side boardcast UDP packet out by setting dest IP to 10.10.10.255. The problem is that the breakpoint I set in the SLOT function processPendingData() for UDP readready signal is never reached, that means my Qt program does not received any UDP packet, although I can see the coming in UDP packet listed in the Wireshark.
I tried to bind UDP to a special port, but it also does not receive any UDP Packet.
@
RemoteContol::RemoteContol(QWidget *parent) :
QWidget(parent),
ui(new Ui::RemoteContol)
{
ui->setupUi(this);connect(ui->UpdateButton,SIGNAL(clicked()),this,SLOT(sendSettingParameters())); //udpSocket.bind(QHostAddress("10.10.10.11"),49166); connect(&udpSocket, SIGNAL(readyRead()), this, SLOT(processPendingData()));
}
void RemoteContol::sendSettingParameters(void)
{
QByteArray datagram;
QDataStream out(&datagram,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_8);
out << "aaabbbccc";
udpSocket.writeDatagram(datagram,QHostAddress("10.10.10.255"),55555);
}void RemoteContol::processPendingData(void)
{
QByteArray datagram;
do {
datagram.resize(udpSocket.pendingDatagramSize());
udpSocket.readDatagram(datagram.data(),datagram.size());
} while (udpSocket.hasPendingDatagrams());
}
@ -
wrote on 1 Mar 2013, 17:02 last edited by
Please use code wrappings as explained "in here.":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01
This makes your code sample readable. -
wrote on 1 Mar 2013, 19:21 last edited by
Just found that if microcontroller side sent data out to Ip 10.10.10.11,desktop can receive it, but if it broadcast it, desktop cannot receive it. Do not know why yet.
-
wrote on 3 Mar 2013, 10:39 last edited by
ubuntu comes with a firewall. Maybe that is getting into the way?
1/4