当STM32模块将STM32设置为一些看似随机但特定的IP地址时,我的Qt程序只接收来自STM32模块的UDP Artnet数据报,我有问题。
因此,我有以下几点:
我编写了Qt软件,并在uIP板上使用了FreeRTOS --修改uIP以正确地使用UDP,并添加了简单的Artnet代码。
它们都在192.168.0.x子网上。
我编写了Qt程序,将Artnet投票发送到子网的广播地址。因此,它将标准的Artnet轮询发送到UDP端口6454,地址为192.168.0.255。Wireshark,显示我的两个STM32模块返回Artnet很好。到现在为止还好。
然而,如果我设置一个STM32的IP地址为192.168.0.177,另一个设置为192.168.0.176,那么Qt程序就会看到和处理177个节点,然而,尽管176个节点发送了正确的Artnet投票回复,Qt程序仍然断然拒绝读取回复数据包。如果我将176个节点的IP地址更改为.44,那么Qt程序将处理答复。如果我将工作的.177节点更改为是,比如说,.43,它就不能工作。
我要强调的是,无论我将STM32s设置到哪个IP地址,Wireshark都表示所有的回复都很好。
有人能提点什么能说明这件事的事吗?我和netcat玩过,但似乎没有读到任何这些Artnet回复,不管它们来自哪个地址,所以我可能误解了netcat能做什么。我用我的Qt程序尝试过netcat,它只打开和输出端口,而不是入站,也没有什么区别,但是,我可能完全误解了netcat或有关UDP的一些东西。也许如果您打开一个出站UDP端口,相同的入站将自动打开?
在我的Linux机器上,没有IP地址冲突,我也没有打开防火墙。
非常感谢。
编辑:按要求添加代码。
void MainWindow::processPendingDatagrams(void)
{
struct ArtNetPollReplyStruct *newReply;
QHostAddress sendingAddress;
quint16 sendingUdpPort;
QString versionString;
QByteArray datagram;
while (udpReceiveSocket->hasPendingDatagrams())
{
datagram.resize(udpReceiveSocket->pendingDatagramSize());
udpReceiveSocket->readDatagram(datagram.data(), datagram.size(), &sendingAddress,&sendingUdpPort);
newReply = (struct ArtNetPollReplyStruct*)(datagram.data());
if (newReply->OpCode == OP_POLL_REPLY)
{
if (sendingAddress != QHostAddress("192.168.0.18"))
{
if (checkAndAddAddress(sendingAddress))
{
versionString = QString::number(newReply->VersionInfoH,10) + "." + QString::number(newReply->VersionInfo,10);
addNodeToList(sendingAddress.toString(), versionString);
ui->textEdit->append( QString::fromUtf8(newReply->LongName));
}
}
}
}
}初始化UDP端口的代码如下:
udpSendSocket = new QUdpSocket(this); udpReceiveSocket = new QUdpSocket(this);
udpSendSocket->bind(6454, QUdpSocket::ShareAddress);
udpReceiveSocket->bind(QHostAddress::Any,6454);
connect(udpReceiveSocket, SIGNAL(readyRead()),this, SLOT(processPendingDatagrams()));
connect(ui->innoLEDListTable,SIGNAL(itemChanged(QTableWidgetItem*)),this,SLOT(tableItemClicked(QTableWidgetItem*)));$ ifconfig
enp5s0 Link encap:Ethernet HWaddr 14:DA:E9:30:36:22
inet addr:192.168.0.18 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:265615 errors:0 dropped:0 overruns:0 frame:0
TX packets:190104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:306893983 (292.6 MiB) TX bytes:20997451 (20.0 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:25205 errors:0 dropped:0 overruns:0 frame:0
TX packets:25205 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:6063842 (5.7 MiB) TX bytes:6063842 (5.7 MiB)
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.0.2 0.0.0.0 UG 10 0 0 enp5s0
169.254.0.0 0.0.0.0 255.255.0.0 U 10 0 0 enp5s0
192.168.0.0 0.0.0.0 255.255.255.0 U 10 0 0 enp5s0发布于 2014-07-02 13:11:51
你只需要一个插座。您的问题是数据报到达您从未读取过的另一个套接字。套接字是双向的。
https://stackoverflow.com/questions/24529039
复制相似问题