dty5753 2016-02-16 15:19
浏览 294

使用golang.org/x/net/ipv4进行多播UDP通信

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!