On Tue, Mar 6, 2012 at 3:36 PM, Jeffrey Baker <jwb...@gmail.com> wrote:
> ListenMulticastUDP function fits in. I want to join the multicast address,
> but I don't think I care about the port. The old JoinGroup took an IP, but
> the new ListenMulticastUDP wants an IP and port both. Does it make any
> difference what I give it for the port?
No it doesn't.
> junk, err := net.ListenMulticastUDP("udp", nil, &net.UDPAddr{IP: mcaddr.IP})
>
> Except that I now have to babysit the lifecycle of "junk" connection that I
> don't need (including the obligatory junk = junk, to make it not unused).
> Am I using this interface correctly?
I guess you need that "junk" to send multicast UDP packets to
on-link multicast neighbors. (or am I missing something?)
package main
import (
"log"
"net"
)
func main() {
nbrs, err := net.ResolveUDPAddr("udp4", "239.255.255.250:1900")
if err != nil {
log.Fatal(err)
}
c, err := net.ListenMulticastUDP("udp4", nil, &net.UDPAddr{IP:
net.IPv4(239, 255, 255, 250)})
if err != nil {
log.Fatal(err)
}
_, err := c.WriteTo([]byte("hello, on-link neighbors!"), nbrs)
if err != nil {
log.Fatal(err)
}
}
Hi,
On Tue, Mar 6, 2012 at 3:36 PM, Jeffrey Baker <jwb...@gmail.com> wrote:
> ListenMulticastUDP function fits in. I want to join the multicast address,
> but I don't think I care about the port. The old JoinGroup took an IP, but
> the new ListenMulticastUDP wants an IP and port both. Does it make any
> difference what I give it for the port?
No it doesn't.
> junk, err := net.ListenMulticastUDP("udp", nil, &net.UDPAddr{IP: mcaddr.IP})
>
> Except that I now have to babysit the lifecycle of "junk" connection that I
> don't need (including the obligatory junk = junk, to make it not unused).
> Am I using this interface correctly?
I guess you need that "junk" to send multicast UDP packets to
on-link multicast neighbors. (or am I missing something?)
c, err := net.ListenMulticastUDP("udp4", nil, &net.UDPAddr{IP:
net.IPv4(239, 255, 255, 250)})
_, err := c.WriteTo([]byte("hello, on-link neighbors!"), nbrs)