问题
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));
}
}
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.
What am I missing?
[Edit] 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?
回答1:
Windows 7 handles 255.255.255.255 broadcast in a different way. More info here: Send UDP broadcast on Windows 7
来源:https://stackoverflow.com/questions/6290329/why-is-my-udp-broadcast-failing