我正在尝试发送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没有看到流量?我已尝试使用另一个在同一端口上广播的应用程序,来自该应用程序的流量显示正常。
我错过了什么?
[编辑] 我刚刚在the UdpClient documentation底部发现一条帖子,指出在Windows 7计算机上发送到255.255.255.255不起作用。虽然整个o / s不是这样,或者从255.255.255.255的其他应用程序的广播失败了?