【问题标题】:UdpClient receives packets to 127.0.0.1 but fails to get them for interface IP addressUdpClient 接收到 127.0.0.1 的数据包,但无法获取接口 IP 地址
【发布时间】:2015-01-26 15:34:42
【问题描述】:

我有一个奇怪的问题,当发送到环回接口的数据包被成功接收,但是发送到本地网络接口的相同数据包丢失并且从未收到:

let test (local:IPEndPoint) =
    Async.Parallel [
        async {
            use client = new UdpClient()
            client.ExclusiveAddressUse <- false
            client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true)
            client.Client.Bind(local);

            printfn "Listen: %A" local.Address

            while true do
                let mutable remote = local
                client.Receive(&remote) |> ignore
                printfn "%A: %A" local.Address remote.Address
        };
        async {
            while true do
                do! Async.Sleep 500

                use senderUC = new UdpClient()
                senderUC.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true)
                senderUC.Send([|byte(1)|], 1, local) |> ignore

                printfn "sent to %A" local
        }
    ] |> Async.RunSynchronously

// this one works
test(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5353)) |> ignore

// this one does not
//test(new IPEndPoint(IPAddress.Parse("10.211.55.3"), 5353)) |> ignore

ipconfig:

C:\Users\Alex>ipconfig

Windows IP Configuration

Ethernet adapter vEthernet (Intel(R) PRO 1000 MT Network Connection Virtual Switch):

   Connection-specific DNS Suffix  . : localdomain
   IPv4 Address. . . . . . . . . . . : 10.211.55.3
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.211.55.1

Wireshark 显示发送的数据包(重新路由到默认网关后)。

Windows 防火墙已关闭。

我不知道要测试什么...

【问题讨论】:

    标签: .net sockets f# udpclient


    【解决方案1】:

    嗯,5353 是 Apple Bonjour 服务 (Zeroconf)。因此,当 Bonjour 运行时,它会在这些数据报到达客户端之前捕获它们。在服务中禁用它会将数据包泵入我的应用程序。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-05
      • 2010-12-26
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多