Using Go 1.5.2 and the standard net package I've implemented an UDP multicast sender and receiver for Windows. However, because of some issues sending MC UDP package through a router, I'm re-implementing it using golang.org/x/net/ipv4.
For the 2 functions below, the first one is able to receive multicast UDP, the socond one not. Can someone please tell me what's wrong?
Never returns from ReadFrom:
import (
"golang.org/x/net/ipv4"
"net"
...
)
func fails(intf net.Interface, mcaddr string, buff []byte) ( n int, err error) {
ipRemote, err := net.ResolveUDPAddr("udp", mcaddr)
// error check
c, err := net.ListenPacket("udp4", ":0")
// error check
p := ipv4.NewPacketConn(c)
// error check
err := p.JoinGroup(intf, &ipRemote)
// err check
n, _, _, err = p.ReadFrom(buff) // never returns
// error check
}
Returns data:
func succeeds(intf net.Interface, mcaddr string, buff []byte) ( n int, err error) {
ipRemote, err := net.ResolveUDPAddr("udp", mcaddr)
// error check
conn, err := net.ListenMulticastUDP("udp", intf, ipRemote)
// error check
n, err = conn.Read(buff) // Returns when data is received
// error check
}
I'm using, e.g., 224.4.3.224:60300, for mcaddr. Using exactly same arguments for both functions, the first fails and the second succeeds.
The first function is implemented based on https://godoc.org/golang.org/x/net/ipv4. Windows does not support the p.SetControlMessage()
function used there.