Just survived the same problem and wanted to share what fixed it for me.
In short: it seems that the Windows firewall was somehow the cause of this strange behavior, and simply disabling the service does not help. You must explicitly allow incoming UDP packets for a specific program (executable file) in the list of incoming Windows firewall rules.
To describe the full case, read on.
My network setup: the IP of my (receiving) machine was 192.168.1.2, the IP address of the sending machine was 192.168.1.50, and the subnet mask on both machines was 255.255.255.0. My machine is running Windows 7 x64.
This is the code (approximately) that I used:
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint iep = new IPEndPoint(IPAddress.Any, 0); sock.Bind(iep); sock.EnableBroadcast = true; EndPoint ep = (EndPoint)iep; byte[] buffer = new byte[1000]; sock.ReceiveFrom(buffer, ref ep);
This initially did not work unless I sent a broadcast packet from this socket before I call ReceiveFrom on it. That is, adding this line before calling ReceiveFrom :
sock.SendTo(someData, new IPEndPoint(IPAddress.Broadcast, somePort))
When I did not send the broadcast packet first from the receiving socket, the incoming broadcast packets were not accepted by them, although they appeared in Wireshark (the packet destination was 255.255.255.255).
I thought it was like a firewall messing around with incoming packets (unless some UDP hole opens first with an outgoing packet - even if I haven't heard before punching UDP holes is applicable to broadcast packets in some way) so I went to services and turned off the Windows Firewall service in general. This has not changed anything.
However, after trying everything else, I turned on the firewall service again and tried to start the program again. This time a firewall prompt appeared asking me if I want to allow the MyProgram.vshost.exe process (I was debugging Visual Studio) through the firewall, I accepted it, and voila - it worked! Incoming packages have been received now!