Google Go: 绑定多播套接字

huangapple go评论94阅读模式
英文:

Google Go: binding multicast socket

问题

Google Go不允许将UDP套接字绑定到多播地址。如果地址是多播地址,它只会将地址设置为零(请参见src/pkg/net/sock_posix.go,listenDatagram函数)。

问题是:我是否可以绕过这个限制?如果不能,是否有一些第三方套接字库或一些C代码可以帮助?

英文:

Google Go doesn't allow to bind UDP socket to multicast address. It just sets address to zero if it is multicast (see src/pkg/net/sock_posix.go, listenDatagram function).

The question is: can I somehow bypass this limitation? If not, is there some 3rd party socket library or piece of C code that could help?

答案1

得分: 1

你可以使用net.ListenMulticastUDP来创建一个监听的多播UDP套接字。它会为你创建套接字,并将其绑定到所需的网络接口和多播组地址。

要获取作为第二个参数传递的接口,你可能想使用net.InterfaceByNamenet.Interfaces

英文:

You should be able to create a listening multicast UDP socket with net.ListenMulticastUDP. It will take care of creating the socket for you and binding it to the desired network interface and multicast group address.

To get an interface to pass as the second argument,, you probably want to use either net.InterfaceByName or net.Interfaces.

huangapple
  • 本文由 发表于 2014年7月2日 09:04:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/24521407.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定