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.