TCP is a connection oriented stream over an IP network. It guarantees that all sent packets will reach the destination in the correct order. This imply the use of acknowledgement packets sent back to the sender, and automatic retransmission, causing additional delays and a general less efficient transmission then UDP.
UDP a is connection less protocol. Communication is datagram oriented. The integrity is guaranteed only on the single datagram. Datagrams reach destination and can arrive out of order or don't arrive at all. Is more efficient than TCP because it uses non ack. It's generally used for real time communication, where a little percentage of packet loss rate is preferable to the overhead of a TCP connection.
Here I am trying to highlight the difference between these protocols?
TCP is connection-oriented protocol. When a file or message send it will get delivered unless connections fails. If connection lost, the server will request the lost part. There is no corruption while transferring a message.
UDP is connectionless protocol. When you a send a data or message, you don't know if it'll get there, it could get lost on the way. There may be corruption while transferring a message.
If you send two messages along a connection i.e. TCP , one after the other, you know the first message will get there first. You don't have to worry about data arriving in the wrong order.
Where as If you send two messages out in UDP, you don't know what order they'll arrive in i.e. no ordered
When the low level parts of the TCP "stream" arrive in the wrong order, resend requests have to be sent, and all the out of sequence parts have to be put back together, so requires a bit of work to piece together.
In UDP No ordering of messages, no tracking connections, etc. It's just fire and forget! This means it's a lot quicker, and the network card / OS have to do very little work to translate the data back from the packets.
In TCP Data is read as a "stream" with nothing distinguishing where one packet ends and another begins. There may be multiple packets per read call.
In UDP Data is read as a Datagrams: Packets are sent individually and are guaranteed to be whole if they arrive. One packet per one read call.
Examples of TCP:
www (Apache TCP port 80)
e-mail (SMTP TCP port 25 Postfix MTA),
File Transfer Protocol (FTP port 21) and
Secure Shell (OpenSSH port 22) etc.
Examples of UDP:
Domain Name System (DNS UDP port 53),
streaming media applications such as IPTV or movies, Voice over IP (VoIP),
Trivial File Transfer Protocol (TFTP) and
online multiplayer games etc