Hello,
I have done some more testing and seen that the issue happens when there are multiple multicast listeners on the same box. Single listeners receive message just for their group but once a second listener joins any other group all listeners receive all groups messages.
Here is the code I'm testing with:
package main
import (
"flag"
"fmt"
"net"
"strings"
)
func main() {
gf := flag.String("group", "", "UDP group")
pf := flag.Int("port", 0, "UDP port")
flag.Parse()
g := *gf
p := *pf
if a, e := net.ResolveUDPAddr("udp4", fmt.Sprintf("%v:%v", g, p)); e == nil {
if c, e := net.ListenMulticastUDP("udp4", nil, a); e == nil {
b := make([]byte, 1024)
for {
n, _, _ := c.ReadFromUDP(b)
fmt.Printf("Read %v\n", strings.TrimSpace(string(b[0:n])))
}
} else {
fmt.Printf("%v\n", e)
}
} else {
fmt.Printf("%v\n", e)
}
}
I run 1 instance up:
go run ut.go -group 239.1.1.50 -port 10000
and then:
netcat -v -u 239.1.1.50 10000
50
gives 50 on stdout.
If I then start another instance:
go run ut.go -group 239.1.1.51 -port 10000
and
netcat -v -u 239.1.1.51 10000
51
both instances get 51 on their stdout.
Likewise if I then
netcat -v -u 239.1.1.50 10000
50
both instance get 50 on their stdout.
netstat shows:
sudo netstat -napug
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
IPv6/IPv4 Group Memberships
Interface RefCnt Group
--------------- ------ ---------------------
eth0 1 239.1.1.51
eth0 1 239.1.1.50