In this paper we have explored the basic workings of the TCP state transition for the teardown phase. We have described these transitions for normal communication and have discussed scenarios that arise when specific network error conditions cause packet-loss during this phase. The timing and nature of packet loss has differing types of impact on the TCP connection state, and states that are normally transient (and difficult to observe) become long-lasting. Network applications that fail to handle such scenarios properly can lead to excessive resource utilization and may suffer from degraded performance. Thus, we hope that the insights into the TCP state transitions provided in this article will be valuable to web developers and devops teams to debug and fix such issues.
The ESTABLISHED state, which corresponds to the data transfer phase of TCP connection, is perhaps the simplest one to understand. In this state, whenever a data packet is received, an acknowledgement is sent back. However, in real life, all performance-related issues for general network communications correspond to this state. Any discussion on TCP communication always entails congestion control and flow control, and both these issues are dealt with in the ESTABLISHED state. These two error-control mechanisms are often (erroneously) perceived to be the same, because the TCP response to both these errors results in same action. In fact, the two error conditions are quite different. Similarly, TCP fairness (the issue of how to allocate bandwidth when a single physical link of limited bandwidth is shared among multiple TCP connections) also corresponds to this state. In our next article, we will discuss the ESTABLISHED state in detail, and aspects of TCP performance or throughput when the network has limited bandwidth or is witnessing packet-loss.
Partial code for TCP client program to demonstrate FIN_WAIT1, CLOSE_WAIT and TIME_WAIT state. The complete program is accessible at .
srvr_addr = (ip_addr, port)
sock = socket.socket(socket.AF_INET,
for i in range(1,count):
#msg = chr(64 + i) * buffer + "\n"
msg = datetime.datetime.now().
print "Sending: " + msg,
sent = sock.send(msg)
9 Experiential Exercises
All the example exercises discussed in this article make use of i) Linux built-in commands related to network utility nc for data transfer, ii) netstat for monitoring network connection state, and a simple python program (tcp_client.py) to enable timing the packet transmission and respective finer control. If at your Linux installation, the netstat utility is not installed, then same can be installed by using the command sudo apt–get install net–tools. Similarly, the netcat (nc) is available by default on all Linux and Apple Mac machines, and for Windows based systems, there are free open source versions available, which can be downloaded and installed. To develop a lasting understanding, it is suggested that reader should carry out all the experimental exercises. The reader should explore even the different sequencing of steps such as firewall rules, packet loss, etc. to help consolidate the understanding.
-  RFC 793, “Transmission Control Protocol”, Information Sciences Institute, USC, CA, Sep 1981, https://tools.ietf.org/html/rfc793. Last accessed Feb 2019.
-  Ram Rustagi, Viraj Kumar, “Understanding Transport Layer Basics”, ACCS journal of Computing and Communications, Vol 2, Issue 3, Sep 2018. https://acc.digital/experiential-learning-of-networking-technologies-understanding-transport-layer-basics/, last accessed Feb 2019.
-  netstat: man page, http://manpages.ubuntu.com/manpages/bionic/man8/netstat.8.html, Accessed Feb 2019.
-  netstat usage examples: https://www.tecmint.com/20-netstat-commands-for-linux-network-management/, Accessed Feb 2019.
-  Netcat (nc) command utility, http://manpages.ubuntu.com/manpages/xenial/man1/nc.traditional.1.html, last accessed Feb, 2019.
-  nc cheat-sheet, https://www.sans.org/security-resources/sec560/netcatcheatsheetv1.pdf, last accessed Feb 2019.
-  Iptables tutorial. https://www.frozentux.net/iptables-tutorial/iptables-tutorial.html, last accessed Feb 2019.
-  Ram Rustagi, Viraj Kumar, “Understanding TCP States – Part I”, ACCS journal of Computing and Communications, Vol 2, Issue 4, Dec 2018; https://acc.digital/experiential-learning-of-networking-technologies-understanding-tcp-states-part-1/, last accessed Feb 2019.
-  Example details for TCP Connection state during connection setup, https://github.com/rprustagi/EL-TCP-States-1.git. Last accessed Feb 2019.
-  Example details for TCP Connection state during tear down phase, https://github.com/rprustagi/EL-TCP-States-2.git. Last accessed Feb 2019.