Transmission Control Protocol

Relevant RFCs

  • RFC675 - Definition
  • RFC793 - IPv4
  • RFC1122 - Clarified a number of TCP protocol implementation requirements
  • RFC2581 and RFC2009 - Congestion control

The programmer interacts with TCP via sockets. There is a separate socket for each connection. Servers and clients operate different with regards to setting up a connection. The server is bound to an address and waits for a connection to be initiated. The client actively connects to the server.

The TCP protocol runs inside the operating system. The complexity is hidden from the programmer. Exceptions would be thrown if the connection drops.


TCP - Three key features

Maintains a reliable connection between hosts. Therefore it does a lot of work behind the scenes for the programmer. It manages efficient packaging and transmission of network traffic.

Virtual circuits

TCP connections are like live, two way connections between hosts. They give the illusion of a proper circuit between two hosts.

Reliable connections

TCP guarantees delivery of data.

Performance optimisation

Includes mechanisms to modify transmission variables depending on network conditions.

How it is achieved

TCP uses a Finite State Machine (FSM) at each end of the connection. This is implemented in software within the operating system. Remember that there is one FSM for every TCP connection (ie socket) within the OS - so heavy workload to maintain many connections.

TCP exchanges events between the two ends to drive state transitions. The events are bit flags which are set (or not) in the TCP header.

Finite state machines

A finite-state machine (FSM) or finite-state automaton (FSA), finite automaton, or simply a state machine, is a mathematical model of computation.

It is an abstract machine that can be in exactly one of a finite number of states at any given time. The FSM can change from one state to another in response to some external inputs; the change from one state to another is called a transition.

A FSM is defined by a list of its states, its initial state and the onditions for each transition. There is a FSM at each side of the connection.

TCP header

TCP flag bits


Set to 1 if the urgent pointer is in use.


Indicates acknowledgement number is valid.


Data in the TCP segment should be sent to application as soon as possible. Data is pushed to the application.


Connection must be reset.


Synchronisation is taking place


Finish, no more data needs to be sent.

Three-way handshake

Host A and Host B

  1. Send a TCP open request with SYN bit set and an initial sequence number of 167.
  2. Receive the open request
  3. Send back a frame with a sequence number of 498, and Acknowledgement number of 168.
  4. Receive the acknowledgement frame.
  5. Send back an acknowledgement number of 499.
  6. Receive the acknowledgement frame
  7. The handshake is complete.

TCP uses 3-way handshake to guarantee that connections are established or terminated correctly. Three messages are exchanged. SYN segment is used to describe messages which create a connection. FIN segment is used to describe messages which close a connection.


Flow control

The TCP flags allow signalling between either end to control the flow rate of data. Basically the number of unacknowledged bytes of data.

Window sizing

The windowing process essentially allows for either side to tell the other how much data it can receive at any instant. Prevents buffer over runs for example. This is achieved by the event flags and sequence numbers.