4

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?

Jon Cage
  • 36,366
  • 38
  • 137
  • 215
  • Are you receiving it on one of the machines in the broadcast domain? – Tony The Lion Jun 09 '11 at 09:05
  • I was just watching the outgoing traffic. If it works, the remote machines will send a response which also shows up on wireshark from the other application. – Jon Cage Jun 09 '11 at 09:09
  • If I change the broadcast address to the range I'm aiming at (10.10.5.255) it works fine so why is it failing for 255.255.255.255? – Jon Cage Jun 09 '11 at 09:10
  • I think you'll need to use your subnet's broadcast address, and not the *this network* broadcast address, which is the one you're trying to use. That broadcast address will not go past any routers – Tony The Lion Jun 09 '11 at 09:16
  • True, but I don't have any routers between my desktop and the remote machine so not too much of a worry there. – Jon Cage Jun 09 '11 at 12:42

1 Answers1

4

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

Community
  • 1
  • 1
Ladislav
  • 418
  • 4
  • 8