4

There are some ios sip applications who are able to communicate with a UDP only SIP Server.

As I know iOS allows only TCP connection to remain open in the background but most of the SIP providers are supporting only UDP.

I have noticed that iOS application 3CXPhone has a "NAT helper mode" and it is able to keep the communication in background with a 3CX Phone system who is UDP only. Dose anyone know what trick do they use? I am developing an SIP app and I have to make it work for the UDP only SIP providers.

I know there are multiple questions regarding UDP socket in background on SO but none of them has a useful answer or the solution proposed there dose not work anymore (starting from iOS 6).

Until now I am aware of 2 possible solutions: 1. Use some GPS events and during that events maintain the socket communication too. After that try to trick apple and get your app in the store. 2. Use a SIP proxy in the middle (B2BUA). But in the 3CXPhone "NAT helper mode" I am not seeing any sip proxy configuration.

alinoz
  • 2,822
  • 22
  • 38
  • possible duplicate of [iOS 4 VOIP app responding in the background](http://stackoverflow.com/questions/3478344/ios-4-voip-app-responding-in-the-background) – tc. Mar 09 '13 at 00:13
  • @tc. I am aware of that question and of another 10 who may look similar but all of them are dealing with the problem at the socket level. Unfortunately the wrapping of the UDP socket dose not work anymore. – alinoz Mar 09 '13 at 08:14
  • I am pretty disappointed by the vote to close this question, I have a problem and I am looking for a solution. If the question is not properly formatted you should help me reformat the question and not to close it. – alinoz Mar 09 '13 at 08:21
  • This question is about how to have an app traverse a NAT. – Frank Shearar Mar 09 '13 at 08:55
  • @FrankShearar: yes and no. The problem is iOS allows only the TCP socket to be remain open in the background and keep the NAT open. But in some SIP providers support only UDP, so I am looking for a solution how to keep the NAT transverse open in this case. – alinoz Mar 09 '13 at 11:58
  • @alinoz I thought that's what I just said. Keeping the UDP bindings alive after you've punched the hole is most of the point of NAT traversal. – Frank Shearar Mar 09 '13 at 12:06
  • @FrankShearar: yes, Frank but how to implement something like that without braking apple rules. The answer provided by chr bellow is correct from this perspective but if apple finds out it will reject my app because of the background mode restrictions. – alinoz Mar 09 '13 at 19:33

1 Answers1

0

If you really need a UDP socket you will need a few things:

  • UIRequiresPersistentWiFi: to ensure that iOS connects to Wi-Fi and doesn't turn it off after some time (I'm assuming you want Wi-Fi as well, if not just ignore this one)
  • Play an empty audio in the background in a loop to keep your application active.
  • Have a timer that pops every ten seconds or so and sends a small (e.g. crlf) message to the server.

The last step is needed to keep the UDP connection open in the network. If you don't send anything often, someone in the network (e.g. a router) will close it.

The empty audio file is the only way to ensure you can do something in the background in short intervals (the ten second timer).

After writing all that: this will consume a lot of battery. Users will not leave your app running for long.

Most modern SIP servers support TCP. You should really spend your time on a TCP solution. The UDP one won't be accepted by your users.

Christian Garbin
  • 2,512
  • 1
  • 23
  • 31
  • RFC 3261 _requires_ TCP (section 18.2.1), but (a) the proxy might be ancient and implement RFC 2543 and (b) sometimes people ignore "MUST" in RFCs... – Frank Shearar Mar 09 '13 at 20:12
  • I don't think it does require TCP. Can you quote RFC 3261 text that requires TCP? Section 18.2.1 says that if a server supports UDP it must also listed for that port in TCP. It doesn't say it's TCP only (or I misread it). – Christian Garbin Mar 09 '13 at 20:30
  • Indeed: if a SIP server supports UDP it _must_ also support TCP. And since noone actually uses SCTP... – Frank Shearar Mar 09 '13 at 20:52
  • For my problem the server supports TCP but just the providers have filtered (firewall) the TCP part. :( – alinoz Mar 10 '13 at 00:34