我无法通过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
(第3919行)中调用doSend
。此调用返回-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
非常感谢任何帮助!
答案 0 :(得分:2)
我已经解决了我的问题,我成功通过IPv6 UDP多播进行发送/接收。问题结果是问题的组合。
IPV6_MULTICAST_IF
不执行的套接字选项GCDAsyncUdpSocket
。 (接收似乎不需要它。)NSObject
,或者被搞砸!没有警告,没有错误,委托根本就没有被调用。