iOS 6 and continuous receiving udp package using gcdasyncsocket

350 views Asked by At

I have problem with continuous receiving udp package with gcdasyncsocket. It's like iP5 iOS6 and iP4 iOS6 receive package for 200-300 ms then stop for another 200-300 and start receiving again. I run some test with iPhone 5 iOS7, iPhone 4 iOS 6 and iPhone 5 iOS6. Results confirm that issue appears only with iOS 6.

Tests

Code is not something sophisticated, is simple as it can be, sending to broadcast adress "230.0.0.1", and receiver socket join to group "230.0.0.1".

Sender

_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++;
}

Receiver

_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");
}

How can I continuously receive? Did you met a similar problem?

Update

I run some test on with iP5 iOS7 -> 6.1 simulator and iOS 6.1 simulator -> iP5 iOS7. In both cases I have continuous receiving.

Update v2

I run tests again but now with simulator 6.0 and again I have continuous receiving.

1

There are 1 answers

1
Dinesh On

GCDAsyncUdpSocket works asynchronously.. YOu need to use a sync UDP request to achieve the result you want..