gcdasyncsocket で udp パッケージを継続的に受信することに問題があります。これは、iP5 iOS6 および iP4 iOS6 が 200 ~ 300 ミリ秒の間パッケージを受信し、さらに 200 ~ 300 ミリ秒停止して、再び受信を開始するようなものです。iPhone 5 iOS7、iPhone 4 iOS 6、iPhone 5 iOS6 でいくつかのテストを実行しました。その結果、iOS 6 でのみ問題が発生することが確認されました。
コードは洗練されたものではなく、可能な限り単純で、ブロードキャスト アドレス「230.0.0.1」に送信し、レシーバ ソケットはグループ「230.0.0.1」に参加します。
送信者
_udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
[_udpSocket bindToPort:_port error:&error];
[_udpSocket enableBroadcast:YES error:&error];
-(void)processBuffer: (NSData*)data
{
[_udpSocket sendData:data toHost:@"230.0.0.1" port:_port withTimeout:-1 tag:tag];
tag++;
}
レシーバー
_udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
if (![_udpSocket bindToPort:_port error:&error])
{
NSLog(@"Binding to port %i: %@",_port,error);
}
if (![_udpSocket joinMulticastGroup:_address error:&error])
{
NSLog(@"Joining to multicast groupu: %@",error);
}
if (![_udpSocket beginReceiving:&error])
{
[_udpSocket close];
NSLog(@"Error starting server (recv): %@", error);
}
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data
fromAddress:(NSData *)address
withFilterContext:(id)filterContext
{
NSLog(@"IGotData");
}
継続して受け取るにはどうすればよいですか?同様の問題に遭遇しましたか?
アップデート
iP5 iOS7 -> 6.1 シミュレーターと iOS 6.1 シミュレーター -> iP5 iOS7 でいくつかのテストを実行します。どちらの場合も、継続的に受信しています。
更新 v2
もう一度テストを実行しましたが、今はシミュレーター 6.0 で継続的に受信しています。