Timeout not working for GCDAsyncUDPSocket sendData toHost withTimeout

268 views
Skip to first unread message

ClarkS

unread,
Jun 13, 2016, 11:19:49 PM6/13/16
to CocoaAsyncSocket
Hello

I am creating a UDP client in swift. For testing I have a UDP echo server set up on another computer. 

I have created a GCDAsyncUdpSocket. I have called sock.bindToPort(port) and sock.beginReceiving().
I send data with sock.sendData toHost with Timeout 
And I receive data with udpSocket didReceiveData fromAddress withFilterContext

This all works fine when the echo server replies with data.

However, if I shut the echo server down, I get no errors at all. I have my timeout set to 2. When I send a packet and get no reply, didReceiveData fromAddress does not fire. Neither does udpSocket didNotSendDataWithTag. I cannot find a didNotReceiveData or didNotReceiveDataWithTag.

If anyone has gotten timeouts to work for unconnected UDP sockets, how did you get them to work?

Arno Gramatke

unread,
Jun 14, 2016, 2:44:11 AM6/14/16
to cocoaasy...@googlegroups.com
The time out that you can set in sendData() is only the time out for the send operation. It doesn’t have anything to do with the receiving of messages. So if the data could not be sent after two seconds, the time out fires. And „sent“ means having handed the data to the OS to send it, not that the data was sent to the receiving end (and the receiving end really received something - this is impossible to do with UDP on that layer).

GCDAsyncUdpSocket doesn’t have a way to time out on receiving. What you can do is create your own timer and let if fire after two seconds, so that you can deal with this. When you receive an incoming message, reset the timer.

--
You received this message because you are subscribed to the Google Groups "CocoaAsyncSocket" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cocoaasyncsock...@googlegroups.com.
To post to this group, send email to cocoaasy...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cocoaasyncsocket/8235d97b-4f1b-4c81-bb7e-9620b9e6bade%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Clark Sann

unread,
Jun 14, 2016, 7:50:54 AM6/14/16
to cocoaasy...@googlegroups.com
Thank you for your informative reply. You fully answered my question.
You received this message because you are subscribed to a topic in the Google Groups "CocoaAsyncSocket" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cocoaasyncsocket/Xl2ePBFymts/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cocoaasyncsock...@googlegroups.com.

To post to this group, send email to cocoaasy...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages