英文:
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.InterfaceByName
或net.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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论