TCP/IP Layer 4 protocols: TCP and UDP
- Error recovery
- Flow control
- TCP provides a wide variety of services to applications, whereas UDP does not
- Most data-link protocols notice errors (error detection) and discard the frame
- TCP provides retransmission (error recovery)
- TCP avoids congestion (flow control)
- As a result, many apps use TCP
- UDP has an important role in TCP/IP.
- It is used in VoIP and Video over IP, in conferences, live streaming…
- The table below shows services that TCP and UDP provide.
- TCP provides all of them, UDP only the first one in the table.
Transmission Control Protocol (TCP)
- Based on an application’s requirements, we can choose TCP or UDP.
- TCP provides error recovery, but to do so, uses more bandwidth.
- UDP does not have error recovery, therefore uses less bandwidth
- Provides services to the application layer
- TCP performs only part of the functions necessary to deliver the data between applications.
- Regardless of whether two computers are on the same LAN or between the entire Internet, TCP performs the same way
- Message created by TCP, TCP header, followed with application data, is called TCP segment, Layer 4 PDU, L4PDU
Multiplexing using TCP port numbers
- TCP and UDP use multiplexing
- TCP and UDP multiplexing tells the receiving computer to which application to give the received data
- Multiplexing relies on a socket.
- The socket consists of three things: IP address, transport protocol, port number
- The web server will probably have port number 80, but also, the host will have its own dynamic port number
- Dynamic port numbers are above 1024 because from 1-1024 are well-known ports reserved for well-known protocols and applications
- Well known port numbers are used by servers, while other ports are used by clients
- Applications that provide services like FTP, Telnet, web servers…, open a socket using well-known port and listen for connection requests.
- On a client machine, any unused port number can be allocated
- For example, one web server can have 100 hosts connected to it and every host has a different socket. but 100 browsers and applications can also connect to the web server on the same socket (server’s port 80)
Connection establishment and termination of connection
TCP connection establishment
- Connection establishment refers to the process of starting Sequence and Acknowledgement fields in TCP header fields and agreeing on port numbers used.
- TCP three-way-handshake must be completed before data transfer begins
- SYN = synchronize the sequence numbers
TCP connection termination:
- Uses additional flag, FIN (finished)
- Before the device on the right sends ACK,FIN message, it first notifies the application that the connection is going down. it then waits for the acknowledgement from the app and after that sends ACK,FIN.
TCP establishes connection with the another host/server but UDP does not
- Connection-oriented protocol: a protocol that requires the exchange of messages before data begins to travel
- Connectionless protocol: a protocol that DOES NOT require the exchange of messages before data begins to travel
Error recovery and reliability
- TCP provides for reliable data transfer, called reliability or error recovery.
- To accomplish reliability, TCP sequences data in order using Sequence and Acknowledgement fields in the TCP header.
- TCP achieves reliability by combining sequence number field in one direction and acknowledgement field in the opposite direction