为什么我的UDP广播失败? [英] Why is my UDP broadcast failing?

查看:1026
本文介绍了为什么我的UDP广播失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送一个UDP广播,但Wireshark是没有报告任何流量。下面是不发送代码片段:

I'm trying to send a UDP broadcast but wireshark isn't reporting any traffic. Here's the snippet that does the sending:

void SendBroadcast()
{
    String^ ip = "255.255.255.255";
    int port = 30718;
    String^ message = "test";

    UdpClient^ udpClient = gcnew UdpClient();
    udpClient->EnableBroadcast = true;
    IPEndPoint^ ipDest = gcnew IPEndPoint(IPAddress::Parse(ip), port);
    cli::array<unsigned char>^ dgram = Encoding::ASCII->GetBytes(message);
    int bytesSent = udpClient->Send(dgram, dgram->Length, ipDest);

    if( bytesSent != message->Length )
    {
        // Failed to send
        Console::WriteLine(String::Format("Error: Failed to send all data (bytes sent: {0})", bytesSent));
    }
    else
    {
        Console::WriteLine(String::Format("Bytes sent: {0}", bytesSent));
    }
}

据报道,它发送的数据(4字节),所以为什么不看的Wireshark的流量?我试着与广播相同的端口上,并从该应用程序的流量显示了优良的另一个应用程序。

It reports that it's sent the data (4 bytes) so why doesn't Wireshark see the traffic? I've tried with another application which broadcasts on the same port and the traffic from that application shows up fine.

我在想什么?

我只是发现在的其中指出,发送到255.255.255.255 Windows 7的计算机上不工作的UdpClient文档。这不可能是真实的O / S作为一个整体,虽然或从其他应用程序到255.255.255.255将失败的广播?

I just spotted a post on the bottom of the UdpClient documentation which states that sending to 255.255.255.255 on a windows 7 machine doesn't work. That can't be true of the o/s as a whole though or the broadcast from the other application to 255.255.255.255 would be failing?

推荐答案

Windows 7的处理方式不同255.255.255.255广播。更多资讯:发送UDP广播在Windows 7

Windows 7 handles 255.255.255.255 broadcast in a different way. More info here: Send UDP broadcast on Windows 7

这篇关于为什么我的UDP广播失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆