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
data.Address = “255.255.255.255”
data.port = 1203
data.Data = buffer
socket.RouterHops = 64
while (socket.PacketsLeftToSend > 0)
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.