with SIP, when to use TCP not UDP?
Asked Answered
H

5

29

I know pretty the differences between UDP and TCP in general (eg. http://www.onsip.com/about-voip/sip/udp-versus-tcp-for-voip)

Question is, in what circumstances would using TCP as the transport have advantages specifically under SIP VOiP communications?

Hutment answered 26/3, 2013 at 18:29 Comment(0)
P
38

A lot of people would generally associate UDP with voip and probably leave it at that, but in simple terms there are two parts to voip - connection and voice data transfer.

SIP is a very light weight protocol, once the connections is established it's effectively left idle until the infrequent event of someone making a phone call. TCP (unlike UDP) will actually reduce traffic to the server by eliminating need to;

  1. Re-register every few minutes
  2. Refresh/ping server

You can run SIP over TCP and then use (as is recommended) UDP for RTP.

I couldn't help but also point out the obvious things that I have looked over. Eg. number of devices connecting to the server. As the number grows, the equation tilts in UDPs favor. But then you also have to consider SIP User Agents expanding to cover multiple codecs, multimedia, video and screen-sharing. The INVITE packets can start to grow large and potentially run over the UDP single datagram size thereby tilting the equation again in favor of TCP.

All that being said I hope you have enough information to answer the question you were looking to answer.

Hope this helps.

Credit: The wonderful discussion at onSip: https://www.onsip.com/blog/sip-via-udp-vs-tcp

Phyllis answered 26/3, 2013 at 18:45 Comment(2)
Cases in which encryption is needed also comes to mind (although SRTP can also use UDP if I'm not mistaken).Hutment
Yes, and SRTP most often does. Although that becomes a discussion around RTP more than SIP. For SIP security you should look at SIPS(Secure SIP).Phyllis
C
16

SIP over TCP has a significant advantage over UDP for mobile devices. The reason is due to the use of NAT, and how NAT table entries in a wireless router or a cell providers' router are generally timed out much quicker for UDP vs TCP. Since keeping the same NAT table entry is necessary to be able to reliably receive calls, SIP must periodically send out keep-alives to maintain the NAT table entry. The required frequency of keep-alives is much higher for UDP (maybe every 30 seconds) vs TCP (maybe every 15 minutes) thus resulting in noticeably higher mobile device battery usage. Often when you see someone complaining about how their battery usage takes a major hit when using a VOIP client, it's because the client is using UDP.

So, TCP wins out over UDP hands down for mobile devices.

Note that the above assumes you want to be able to reliably receive calls on your mobile device. If all you want to do is be able to make calls, then it's a different story.

Carpetbagger answered 29/1, 2015 at 0:47 Comment(2)
Interesting. One wonders how modern mobiles have their built-in VoIP SIP apps configured by default (eg. Android 4+) in this context.Hutment
any sources for any of this? sending a udp packet every 30 seconds doesn't sound like it could use much battery.Anyone
P
6

If a message is large (within 200 bytes of MTU size), RFC 3261 section 18.1.1 mandates use of TCP (to be precise, it mandates use of a "congestion controlled transport protocol, such as TCP"). I've hit that in practice when sending an initial INVITE with lots of headers and a complex Request URI.

Pyorrhea answered 26/3, 2013 at 20:28 Comment(0)
H
6

You cannot reliably assemble an audio stream from a TCP based protocol. In audio it is far better to lose a packet than to have a packet retransmitted because of a packet drop. Audio does not work if there is excessive jitter in the packet timing. Audio is real-time and requires a protocol like UDP to work correctly. Packet loss does not break audio, it only reduces the quality. TCP's perfect delivery does not help audio in any way, there can be no quality if you get 100% of the packets, but they are not in real time. In audio it is the timing (latency, jitter) that determine quality more than data integrity.

This sip works BEST when signal and control are over TCP but voice data is over UDP.

I have been working with transmission of digital voice over network protocols since I designed one of the first smartphones in 1987 for the newly emerging digital cellular network in Japan. Since 1987, the only aspect of digital voice transmission that has not changed is what I describe here. The real-time nature of audio (voice) transmission and how that impacts system design is still exactly the same as it was in the dinosaur days I come from.

Haematozoon answered 2/9, 2016 at 17:32 Comment(1)
You are right but this is not what is being asked. TCP vs UDP here is for the SIP control stream, not for the RTP audio stream.Hemipode
R
-5

TCP can get through with perfect clarity on a lossy connection, when UDP may not be understandable. You get lower latency with UDP, but that doesn't help you if you can't understand what is being said.

Rolandrolanda answered 1/3, 2016 at 8:33 Comment(1)
SIP does not carry the voice part. That's RDP.Definitive

© 2022 - 2024 — McMap. All rights reserved.