Need help with UDPSocket and Multicast

I’m trying to perform a mDns Browse to obtain the list of devices matching a specific name/pattern.

First, I tried a simple Python script to check if this could work from my Mac (updated to Sequoia 15.1.1) and obtain WireShark traces.

So far, so good.

Then I created a small Xojo (Xojo 2024 release 3.1) class to build the same request binary based on the specs of DNS request and confirmed the results by comparing with the info I retrieved with WireShark.

Finally, I tried to send that request from my Xojo app using a UDPSocket (added to the window), creating a datagram with destination port set to 5353 and address set to 224.0.0.251.

That did not work.

The Wireshark trace obtained when running the Python script shows that the source port and destination port are 5353, which is the mDns port. But when I try to set the port of a UDPSocket to that port, connect() returns an error (105 / Address is in use) I set the port to something else (p.ex.: 8000, I also tried 65000 with same results) and got the UDPSocket to connect.

The request appears in WireShark trace with a source port set to 8000 and a destination port set to 5353.

Then some devices reply with their IP information. Those replies appear in the WireShark trace, but only the first reply reaches the UDPSocket. Adding calls UDPSocket.Poll in the DataAvailable event handler, after pulling the reply with a call to read() does not improve the results.

I added my UDPSocket to a MulticastGroup (using IP 224.0.0.251) but that did not change the behaviour of the UDPSocket.

I moved the UDPSocket from the window to a property of the app object, initialised this object in the open event of the app object and mapped the events to methods with AddHandler. Same results, got only the first reply, if any.

Out of ideas now…

By the way, the documentation about UDPSocket deserves some cleanup, as it contains examples for EasyUDPSocket, TCPSocket, … referring properties or methods that do not exist in UDPSocket.

Code is here:

var zcq as new ZeroConfQuery(0, False, False, False, 0)
zcq.SetTransactionID(1234)

//zcq.AddQuestion(“_shelly._tcp.local”, “PTR”,“IN”)
zcq.AddQuestion(“_http._tcp.local”, “PTR”,“IN”)

var mb as MemoryBlock = zcq.GetMessageBytes

var dtg as new Datagram
dtg.Address = ZeroConfConstants.ZeroConfIPV4
dtg.Port = ZeroConfConstants.ZeroConfPort
dtg.Data = mb

app.UDPSocket1.NetworkInterface = nil //system.NetworkInterface(0)
app.UDPSocket1.Port = 64000
app.UDPSocket1.RouterHops = 64
app.UDPSocket1.SendToSelf = False

// app.UDPSocket1.Port = 5353

app.UDPSocket1.Connect

System.DebugLog("1Is connected " + str(app.UDPSocket1.IsConnected))

if app.UDPSocket1.JoinMulticastGroup( ZeroConfConstants.ZeroConfIPV4) then System.DebugLog(“1Joining multicast group”)

app.UDPSocket1.Write(dtg)

//app.UDPSocket1.Poll