Hello everyone,
I’m trying to learn haxe programming by implementing some toy example projects to evaluate its usage in other multi-platform projects I’m currently working on.
One of these toy projects involves sending an UDP packet to a broadcast address on a specific port. For context, this is done to perform an autodetection of other hosts/services on the local net that are listening on that given UDP port.
When I tried using the sys.net.UdpSocket#sendTo() method to send the packet bytes, I noticed a number of issues:
-
--interp
mode always errors out – this is explained in issue #5501 and I guess I can live without it by compiling to the neko platform; - although the java platform is listed in the “available” platforms in the class docs, the generated java code throws a “Not available on this platform” HaxeException as soon as the class constructor is called – is this a documentation error or did I understand wrong what “availability for platform X” means?
- sending to “normal” addresses works (verified using Wireshark), but when I specify a broadcast address destination (be it
255.255.255.255
or a more specific one, like192.168.0.255
), the UdpSocket#sendTo() function always throws an Exception (see below). I guess the underlying socket needs a flag to be set for correctly broadcasting packets to the destination (like what is done in C viasetsockopt
):
Called from sys.net.UdpSocket::$statics line 1
Called from Main::main line 6
Called from Example1::find line 30
Called from sys.net.UdpSocket::sendTo line 40
Uncaught exception - Custom(std@socket_send_to)
- when using the native binary produced by
hxcpp
, the Exception becomesError : Custom(EOF)
. Is this normal?
All the tests were done on a Linux x86_64 machine using haxe-3.4.7, hxcpp-3.4.188, hxjava-3.2.0.