Saturday 23 August 2014

The differnce between TCP and UDP

Notes to the blog:
http://www.javacodegeeks.com/2014/07/9-differences-between-tcp-and-udp-protocol-java-network-interview-question.html

This question what is the difference between TCP and UDP is often asked during the interviews. It is also important for sysadmin and program to understand for dairy work. Then we will explain what is the major differences we can see between the two protocols.

Connection-oriented vs Connectionless:

this is the essential differnce between TCP and UDP. The differnce also explains the other different points in the blog. when we say TCP is connection-oriented, it means the protocol itself controls and manages the connection session. It needs so-call 3-ways handshake and 4-ways termination. TCP also has many control packages such as SYN,ACK to for flow control. Meanwhile, UDP does not provide a 'connection' session for communication parties.

Reliability:

TCP is reliable as the application can assume TCP provides a reliable communication while UDP does not provide any  delivery guaruntee

Ordering:

TCP also guarantees order of message as it can get the sequence number from all the packages. while UDP does not care about the package sequence.

Data Boundary:

TCP does not preserve data boundary, UDP does.In TCP, data is sent as a byte stream, and no distinguishing indications are transmitted to signal message (segment) boundaries. On UDP, Packets are sent individually and are checked for integrity only if they arrived. Packets have definite boundaries which are honoured upon receipt, meaning a read operation at the receiver socket will yield an entire message as it was originally sent.

Speed:

In one word, TCP is slow and UDP is fast.

Heavy weight vs Light weight:

Because of the overhead mentioned above, Transmission control protocol is considered as heavy weight as compared to light weight UDP protocol. TCP header is longer than UDP headers.

Congestion or Flow control:

TCP does Flow Control. TCP requires three packets to set up a socket connection, before any user data can be sent. TCP handles reliability and congestion control. On the other hand, UDP does not have an option for flow control.

Different Applications:


because TCP and UDP provides different behaviour or characters, different application use either TCP or UDP as their transmission protocal. for example, HTTP and FTP, they use TCP while SIP, TFTP use UDP.

No comments:

Post a Comment