0

I use GCDAsyncSocket to send images in my application.The images are big,so I split its data to many small packets which save in a NSMutablearray called sort.

GCDAsyncUdpSocket *sendSocket;
sendSocket = [[GCDAsycUdpSocket alloc] initwithDelegate:self delegateQueue:dispatch_get_main_queue()];
for(int i = 0;i < sort.count; i++)
{ 
   [sendSocket sendData:[sort objectAtIndex:i toHost:@"239.1.1.110" port:46110 Timeout:-1 tag:1];
}

But every packet sending is too close,most packets will lose.To solve this problem,I add a line of code as follows:

GCDAsyncUdpSocket *sendSocket;
sendSocket = [[GCDAsycUdpSocket alloc] initwithDelegate:self delegateQueue:dispatch_get_main_queue()];
for(int i = 0;i < sort.count; i++)
{ 
   [sendSocket sendData:[sort objectAtIndex:i toHost:@"239.1.1.110" port:46110 Timeout:-1 tag:1];
   [Thread sleepForTimeInterval:0.003f];
}

As a result,it makes my application weird.So I want to know any else way to add timeInterval to every sending.Any help is appreciated,thanks a lot in advance.

X.Rodi
  • 43
  • 10

1 Answers1

0

in GCDAsyncudpSocket.m use this code

            if (socketError.code == ENOBUFS) {
                [self notifyDidNotSendDataWithTag:currentSend->tag   dueToError:[self errnoErrorWithReason:@"Buffer Full"]];
                [self endCurrentSend];
                [self maybeDequeueSend];
                usleep(10000);
            }
Avinash Tag
  • 162
  • 2
  • 12