我正在尝试发送 UDP 广播,但wireshark 没有报告任何流量。这是执行发送的代码片段:
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 看不到流量呢?我尝试过在同一端口上广播的另一个应用程序,并且来自该应用程序的流量显示正常。
我缺少什么?
[Edit]我刚刚在底部发现了一个帖子UdpClient 文档 http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient.aspx其中指出在 Windows 7 计算机上发送到 255.255.255.255 不起作用。但对于整个操作系统来说,情况并非如此,或者从其他应用程序到 255.255.255.255 的广播会失败?
Windows 7 以不同的方式处理 255.255.255.255 广播。更多信息请点击这里:在 Windows 7 上发送 UDP 广播 https://stackoverflow.com/questions/3229317/send-udp-broadcast-on-windows-7
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)