We can send messages to our loved ones and communicate with people over the internet due to the TCP/IP model. The data we send over the internet needs to be accurate and get to the intended person on time and still intact. This is possible due to the TCP/IP model, where data is first broken down into packets and sent over the internet. Once it reaches its intended target, it is reassembled back and sent across to the client. In this post, I will explain how to build a simple TCP/IP connection. Then, we will test it using python’s built-in testing module unit test and the python testing framework called pytest.
What is a TCP/IP connection?
Transmission Control Protocol/Internet Protocol is known by the acronym TCP/IP. It is a collection of guidelines and procedures used to connect network devices over the Internet. It is a data communication protocol that allows computers and devices to send and receive data.
A client or machine (a client) receives a benefit (such as the sending of a webpage) from another computer (a server) on the network when using TCP/client-server IP’s communication model.
The TCP/IP suite of standards is categorized as stateless as a whole, implying that every client request is thought of as being unique because it has no bearing on earlier ones. Being stateless frees up network paths, allowing for ongoing use.
How does a TCP/IP connection work?
We’ll start by talking about how to send a packet over a TCP/IP port.
1. The first step is to establish a relationship/connection
When two computers want to send data over TCP, they must first establish a connection with a three-way handshake.
The SYN bit is set to (SYN = “synchronize?”) when the first machine transmits a packet. The second computer responds by sending a message with the ACK bit set to (ACK = “acknowledge!”) and the SYN bit set to. The first computer responds with an ACK.
In fact, the three packets that make up the three-way handshake often contain no data. The computers are prepared to receive packets containing actual data once the handshake is complete.
2. In the following step, we send data packets
The recipient is always required to acknowledge receipt of a data packet sent over TCP. The first computer delivers a packet containing data and a sequence number. In order to acknowledge it, the second computer sets the ACK bit and increases the acknowledgement number by the size of the data it has received.
Sequence and acknowledgement numbers are contained in the TCP header as shown below:
When the ACK bit is set to 1, it indicates that acknowledgement number contained in the TCP header is valid.
The computers can keep track of which data was successfully received, which data was deleted, and which data was unintentionally sent twice with the use of those two numbers (the sequence number and the acknowledgement number)
3. We then disconnect the connection
Read the full article on our blog. An article by Sarima Chiorlu.