Question

In my application I am using GCDAsyncUdpSocket for UDP Packet communication...

I have written the code like the below

GCDAsyncUdpSocket* UDPSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];

 [UDPSocket sendData:dataForSendToServer toHost:stringForHostId port:portNumber withTimeout:5 tag:1];

I like to use the Timeout property to resend the Packet again if packet has timed out...

In GCDAsyncUdpSocket API Document it says

The timeout for the send opeartion. If the timeout value is negative, the send operation will not use a timeout."

So the Timeout with -1 will work to automatically resend the packets?..or any other way to do it?

Thanks in advance.

Was it helpful?

Solution

I think your understanding of timeout was reversed. Here is the quote from the author's doc "If the timeout value is negative, the send operation will not use a timeout." So to do what you planed, you will need to use a positive value. And you can implement to resend logic in the timeout callback method:

- (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueToError:(NSError *)error;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top