>Have you ever wonder how the email or message you send reaches the other person? It’s a simple process basically but to implement is quite difficult.
In my upcoming posts, I would be giving steps to implement a TCP Stack. For that first, we need to understand the concept on how messages or details get transferred across networks.
There are basically two network models via which we can transfer data:
- OSI (Operating Systems Interconnection Model)
- TCP/IP (Transfer Control Protocol/ Internet Protocol Model)
OSI basically has seven layers across which the data get transmitted. The seven layers of OSI model are:
TCP/IP model has four layers which are explained below in detail along with an example how it works:
- Network access
The Application layer is where user interaction takes place. Application layer makes sure that the data sent in the format which is understandable to the recipient. For example HTTP, FTP etc.
The Transport layer is where the data is broken down into packets by using the TCP/Transfer Control Protocol. It adds segment number and port number. Port number specifies the port to where data should be transferred and segment number makes sure the broken down packages can be reassembled.
The Internet layer makes sure that it reaches the correct destination. The IP/Internet Protocol adds the sender’s and recipient’s IP address. Here we create the socket. The socket is basically used for establishing connections which include the recipient’s IP address and the port number.
The Network access includes both the Data-Link and the Physical Layer in the OSI model. Data-Link makes sure of transmission through Ethernet for instance. Physical layer makes transmissions through Hardware. The Network access layer adds the MAC address of both the sender and receiver.
Here is an example to show the transmission of the message below:
Good morning Aditi!
Above is the message you have in the Application layer, which gets in the below format. Note that I am using XML format here:
Each of them in a gospel tag goes as a separate packet when it enters the Transport Layer.
Here we add the port number as 60 and each of the segment number. Now when it is passed to the IP Layer we have:
We have the IP address of the sender 18.104.22.168 and that of the receiver 22.214.171.124. The socket can be written as 126.96.36.199:60
The Final layer of the Network access Layer would look like:
We have the sender’s MAC address starting with 00 and the receivers starting with 11.
Once the message reaches the receiver there it is unpacked by traveling through the each of the four layers in the reverse order and the segment number makes sure that the packets get arranged in an order.
The next post would be based on setting up a server-client connection to start with the TCP stack!