Wednesday, June 13, 2012

Why should audio and video streams should typically transmitted over UDP instead of TCP?


To better answer this question we need to understand the working of TCP and UDP individually. TCP (Transmission Control Protocol) is a communication protocol on the internet, which routes packets between machines in a best effort fashion. It creates a protocol that guarantees or assures the sender that the packets or in broader view a message will be received by the specified receiver. TCP does this by a process called as TCP sessions. It has three basic components, namely,
1.      Initial SYN request (Handshake)
2.      Reception of SYN-ACK request
3.      Acknowledgement response

This process is also accompanied by sequence numbers that ensure that the packets are received in order and also used to check for completeness of messages.

On the other hand, UDP (User Datagram Protocol) does not have a lot of features as the TCP has. UDP does not make a guarantee that the packets or messages will be received in order and also does not check for correctness or completeness. It also does not have initial handshake as TCP has.

As we can infer from the above descriptions, TCP takes longer time than UDP does. Also in TCP if we are transmitting voice or audio and due to some issue a packet is lost. The receiver would stop accepting any more packets until the missing packets is received which will add latency to the communication and hence will disturb a real time communication. Whereas for the UDP based audio or video communication, even if a packet is lost, we humans are able to fill in the void by pattern recognition or by anticipating the voice and hence communication can occur. Even though there maybe packet loss in UDP communication, it is a more efficient and effective protocol for time-sensitive applications such as voice and audio.