none
UDP broadcast fails in desktop C# client RRS feed

  • Question

  • I am trying to send broadcast message in network using UDP client in C#, but i don't see message received by any listener client in network, how can i troubleshoot?

    I am trying to communicate with unknown IP (micro controller device)/PC, hence i am using broadcast proprietary message on UDP broadcast. i have need to get remote device static IP hence i am using broadcast.

    C# Sender code

    
    IPAddress broadcast = null;
    
    Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
    
    s.EnableBroadcast = true;
    
    // proprietary message for identification 
    byte[] sendbuf = {0x5C, 0x45, 0x6D, 0x62, 0x65, 0x64,
                0x4C, 0x6F, 0x67, 0x69, 0x6B, 0x5, 0x6C, 0x73, 0x74, 0x5, 0x4, 0x5};
    
    broadcast = IPAddress.Parse("255.255.255.255");
    
    IPEndPoint ep = new IPEndPoint(broadcast, 1110);
    
    s.SendTo(sendbuf, ep); // send message

    I used the code from Microsoft site and modified for the IP to 255.255.255.255, however when i use IP 192.168.2.255 (router IP 192.168.2.1) the device (micro controller based device) responds, i also checked with UDP listener on another PC in network, but i dont see listener receiving(another PC) message not also on wireshark when ip is set as 255.255.255.255 for broadcast. To experiment i turned off router and connected PC(sender) and PC(listener) to just switch but there was no message of received on listener.

    when i connect device (micro controller device) directly to PC, it works on both 255.255.255.255 and 192.168.2.255. i dont understand how to troubleshoot when device is in network and why broadcast doesnt work in network.

    need help to resolve this ? in case any point is unclear please notify

    i changed to code from micro controller to output sendto(255.255.255.255) Now when i use directed broadcast (192.168.2.255) i can see both outgoing message from application and as well as incoming message to application (from MCU (255.255.255.255)) on wire shark

    but when i use IP 255.255.255.255 on application for sending message i dont see any packet on wire shark.

    Wednesday, September 11, 2019 8:38 AM

All replies

  • 255.255.255.255 broadcasts never pass through a router.  Imagine the chaos that would erupt if I could do a UDP broadcast that traveled worldwide.

    The right thing to do is use the broadcast address for the subnet you want to see it.


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, September 12, 2019 4:20 AM