Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在Wireshark中看不到从QUdpSocket发送的数据包_C++_Qt_Wireshark_Qudpsocket - Fatal编程技术网

C++ 在Wireshark中看不到从QUdpSocket发送的数据包

C++ 在Wireshark中看不到从QUdpSocket发送的数据包,c++,qt,wireshark,qudpsocket,C++,Qt,Wireshark,Qudpsocket,我试图在Wireshark中查看传出的UDP流量 // create a socket called from init() socket = new QUdpSocket(this); bool ret = socket->bind(QHostAddress::LocalHost, 47000); if (ret == false) { printf("failed to bind socket\n"); } // create and sent som

我试图在Wireshark中查看传出的UDP流量

// create a socket called from init() 
socket = new QUdpSocket(this);
bool ret = socket->bind(QHostAddress::LocalHost, 47000);
if (ret == false)
   {
    printf("failed to bind socket\n");
   }    


// create and sent some data called from send()
QHostAddress addr("192.168.5.12"); // addr of my other computer
qint64 size = socket->writeDatagram(QByteArray("udp data"),addr,47000);

printf("sent %d\n",size); // correct size sent 8
我创建了新套接字并将其绑定到我的QHostAddress::LocalHost,没有任何错误。然后我发送了一些数据writeDatagram,返回值是正确的,但我在Wireshark中没有看到传出流量

// create a socket called from init() 
socket = new QUdpSocket(this);
bool ret = socket->bind(QHostAddress::LocalHost, 47000);
if (ret == false)
   {
    printf("failed to bind socket\n");
   }    


// create and sent some data called from send()
QHostAddress addr("192.168.5.12"); // addr of my other computer
qint64 size = socket->writeDatagram(QByteArray("udp data"),addr,47000);

printf("sent %d\n",size); // correct size sent 8

我检查了防火墙设置,如果我将其关闭,结果相同。

通过将QHostAddress从localhost更改为分配的路由器地址来解决。

您在哪个平台上。你能看到其他环回流量吗?也许可以尝试ping localhost,看看这是否会在wireshark中产生流量……您使用的是什么操作系统?QHostAddress::LocalHost应该解析为wireshark无法在windows(和其他一些)上侦听的环回地址。您在wireshark上侦听的是什么网络设备?@Mike,很抱歉没有说明平台时间是凌晨12点,我工作到很晚。我在Windows7上。在ping localhost时,我看不到任何流量。我将QHostAddress::LocalHost更改为我的网络地址,现在我看到了数据包。谢谢大家的帮助。真不敢相信我没试过。已解决。无需担心:)只有当您能够从
ping localhost
查看ICMP数据包时,才能看到Qt在wireshark上发送的内容。如果您想让wireshark捕获环回流量(虽然我自己还没有尝试过这些指令),您可能需要参考我之前评论中的链接。