The transport layer in the network stack
The fourth level of the OSI stack, the transport layer, has the arduous task of managing end-to-end logical communication between applications.
Transmission Control Protocol (TCP)
TCP is a connection-oriented protocol designed to guarantee the absolute integrity and order of transmitted data.
Before starting the exchange, TCP initiates a formal connection between the client and server through a three-way process (Three-Way Handshake).
The client sends a packet with the SYN (Synchronize) flag to start aligning sequence numbers.
The server responds with a packet containing the SYN and ACK (Acknowledgment) flags to accept the invitation.
The client finally responds with an ACK packet, officially opening the transmission channel.
TCP also takes care of controlling flow and congestion to prevent a sender that is too fast from saturating the receiver.
User Datagram Protocol (UDP)
At the opposite pole is UDP, a connectionless protocol devoid of frills and aimed exclusively at maximizing speed.
It does not perform any initial handshake and does not guarantee that datagrams arrive at their destination or maintain the order of sending.
Its extremely reduced header minimizes network overhead, offering lightning-fast performance.
Fields of application
The choice of protocol depends entirely on the requirements of the application in use.
TCP is mandatory when every single bit is crucial: web browsing (HTTP), email (SMTP), and file transfer (FTP).
UDP is ideal for scenarios where partial data loss is negligible compared to speed: video streaming, online gaming, and VoIP.
Conclusions
The balance between TCP's iron reliability and UDP's immediate agility constitutes the backbone of digital interactivity.