Broadcast UDP to address 255.255.255.255 on windows does not work

In a small app I need to broadcast a UDP packet to address 255.255.255.255 so that any device connected to the LAN will receive it. (I know this should be done with care, and also I cannot use Multicast)
This works fine on MacOS and Linux using Xojo UDPSocket and Datagram classes.
However, on Windows this does not work.

The code could not be simpler. In the run procedure of a console app a buffer is sent using
"
Var socket as new UDPSocket
Var data as new Datagram
socket.Connect
data.Address = “255.255.255.255”
data.port = 1203
data.Data = buffer
socket.RouterHops = 64
socket.Write(data)
while (socket.PacketsLeftToSend > 0)
socket.Poll
wend
socket.Close
"

This has to do with some security issues on Windows. I tried similar code in CSharp which throws an exception on any other address than the current subnet. So the default libraries in Windows do not like 255.255.255.255 as broadcast destination. (Although CSharp even defines ‘IPAddress.Broadcast’ as a synonym for ‘255.255.255.255’.)

Oddly, similar code in Python runs on Windows without a problem and transmits the packet without any issue.

I need to deliver this an executable for Windows and Mac so any pointers to make this work with Xojo on windows is appreciated.

I just tested it and it worked fine for me going between my main and a vm using 2020r1.2.

If you post up two simple binary projects (send and receive) I’ll test them here and see if I can spot anything obvious.

Ok, I have to look again what this issue is. So it must be me… (As usual ;-))

As usual egg on my face again:

It does work, as long as you filter on the correct ip adres in Wireshark. :face_with_hand_over_mouth:
My VM off course has a different IP address. :roll_eyes:

Thanks for pointing out it does work.

This show that one should not always follow your first thought, but take a step backwards before you dig into the issue.

Nothing to do with security and works better than CSharp. Because that does throw an exception. :wink:

1 Like