4

My question is not actually what is the code to keep UDP socket alive when application in background but a confusion about the documentation in apple developer site.

According to apple developer guide if i set kCFStreamNetworkServiceType to kCFStreamNetworkServiceTypeVoIP then this socket will be managed specially by system when app in background.

enter image description here

In CocoaAsyncSocket library they reported that this settings is not working in UDP socket but only in TCP socket. I also tested this option for native CFReadSteam interface but socket didn't alive when app was in background. But apple developer site never mention it. enter image description here

Is this true that only tcp socket can keep alive in background or i am making any mistake in my code?

shantanu
  • 2,408
  • 2
  • 26
  • 56
  • I won't tell for Apple and this specific code, but it is worthy to point out that UDP is connectionless protocol. There is no such thing as "keeping alive" in UDP, you keep a live connection and UDP stateless. The name "UDP socket" might be misleading here. Even though your socket can be "connected" - that just means that your OS stores the peer IP address and UDP port number in kernel space, but there is no state being associated with this "connection" to be maintained and, therefore, there is nothing to "keep alive". – wick Jun 19 '14 at 10:53
  • @wick I am sorry that my post confused you. I am actually want to keep open the udp socket(receiver). When application goes to background(in iPhone), system close the socket. So if someone send me data in udp port while my app in background then i can't receive that. – shantanu Jun 19 '14 at 20:26
  • did you ever get an answer on this? – Jeef Oct 25 '15 at 16:20
  • 2
    Unfortunately no, Only way is TCP socket for now. – shantanu Oct 25 '15 at 17:04

0 Answers0