TCP and UDP

While IP takes care of routing messages to and from systems across different networks by means of IP address, Transport level protocols try to make sure that the messages get to their intended destination on time, and in the right order.

TCP is perhaps the most common Transport layer protocol. It enables two-way communication by establishing a session between machines. A TCP session is initiated by what's called the Three Way Handshake. Here is how it works:

  1. Machine A send a packet with a flag called SYN (or synchronize) to Machine B.
  2. Machine B receives the SYN flag, and sends back a packet with the SYN-ACK flag to acknowledge Machine A.
  3. Machine A receives the SYN-ACK and finally sends back an ACK flag to acknowledge Machine B.

With these three steps, both machines know reliably that each of them are receiving each others' messages. The session is now open, and the two machines can now send segments back and forth.

In addition to the feature of robust sessions, TCP adds the concept of ports. Whereas an IP packet requires the sender to specify an IP address, a TCP segment requires the sender to specify a port number between 0 and 65535 (2^16 - 1). Ports 0 to 1023 are considered well-known ports, and are frequently used by extremely popular network services. Essentially, TCP ports allow a machine to open up multiple communication sessions at the same time.

Some network services do not require the reliable two-way communication provided by TCP, and simply need to send and receive one-way messages. Instead of going through the work of establishing a session, a machine transmitting via UDP simply sends its message and assumes that the other machine received it.


Relevant Note(s): Network Protocols