我无法让 IPv6 上的 UDP 多播工作。我正在尝试执行此操作的平台是 iOS(使用 Swift)。我有一个GCDAsyncUdpSocket
并像这样配置它:
self.socket!.setIPv4Enabled(false)
self.socket!.setIPv6Enabled(true)
do {
try self.socket!.bindToPort(Announcement.ipv6BroadcastPort, interface: "en0")
}
catch let error {
print("bind failed: \(error)")
throw error
}
do {
try self.socket!.joinMulticastGroup("ff32::5222", onInterface: "en0")
}
catch let e {
print("join multicast failed: \(e)")
}
之后,我尝试将一些数据发送到多播地址:
socket.sendData(data, toHost:"ff32::5222", port: 21026, withTimeout: 5, tag: 0)
那时,当单步执行 GCDAsyncUDPSocket 代码时,我最终调用sendto
了方法doSend
(第 3919 行)。此调用返回 -1,错误是“没有到主机的路由”。我在 iOS 模拟器中运行它。当我枚举所有可用的网络接口时,我得到了这个:
Name: lo0
Address: Optional("::1ebc:680b:100:0")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
Name: lo0
Address: Optional("::2bc:680b:100:0")
Family: NetUtils.Interface.Family.ipv4
Supports multicast: true
Name: lo0
Address: Optional("fe80::1ebc:680b:100:0")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
Name: en0
Address: Optional("fe80::1ebc:680b:100:0")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
Name: en0
Address: Optional("2001:984:3427:1:1ebc:680b:100::")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
Name: en0
Address: Optional("2001:984:3427:1:1ebc:680b:100::")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
Name: en0
Address: Optional("::2bc:680b:100:0")
Family: NetUtils.Interface.Family.ipv4
Supports multicast: true
Name: awdl0
Address: Optional("fe80::1ebc:680b:100:0")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
Name: utun0
Address: Optional("fe80::1ebc:680b:100:0")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
Name: utun0
Address: Optional("fde6:4b33:67e4:9d5e:1ebc:680b:100::")
Family: NetUtils.Interface.Family.ipv6
Supports multicast: true
任何帮助深表感谢!