I\'m working on a Go program that sends out a UDP broadcast to query existence of devices on the local network and then reads the replies. Using Wireshark I confirm that the
You need to use ListenUDP
instead of DialUDP
. When you use DialUDP
, it creates a "connected" UDP port, and only packets originating from the remote address are returned on read.
conn, err = net.ListenUDP("udp", ourAddr)
Since the connection doesn't have a default destination, you will also need to use WriteTo*
methods to send packets:
sendLen, err := conn.WriteToUDP(discoverMsg, serverAddr)