1

GCDAsyncUdpSocket在 iOS 上使用(成功)使用 UDP 发送和接收数据,如下所示:

udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate: self delegateQueue: dispatch_get_main_queue()];
NSError *error;
BOOL result = [udpSocket bindToPort: 3054 error: &error];

设备在端口 3054 上发回数据,我使用委托调用看到了该端口udpSocket:didReceiveData: fromAddress:withFilterContext:。该设备还在端口 9750 上发送信息,我也想看看。我试过不绑定到特定端口,但由于其他原因失败了。我也尝试过使用

udpDataSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate: self delegateQueue: dispatch_get_main_queue()];
NSError *error;
BOOL result = [udpDataSocket bindToPort: 9750 error: &error];

虽然这些调用成功且没有错误,但我没有从端口 9750 获取数据。

我确实知道正在发送数据;这是iOS方面的问题。我知道这是因为:

  1. 逻辑分析仪在端口 9750 上看到数据到达设备进行传输;这是暗示性的,但不是决定性的。

  2. 我可以将设备用于发送第二个数据流的端口切换到 3054,在这种情况下,我的应用程序会看到数据。不过,这是不可取的。

那么,如何在 iOS 上使用相同的 IP 地址从两个 UDP 端口读取数据GCDAsyncUdpSocket

4

0 回答 0