TCP is a connection oriented protocol which helps two devices to communicate over a network. Here “Connection oriented” means that there is a proper connection between the two devices to help us have reliable connection over an unreliable network. For TCP, a connection between the two devices is required.
First of all, we need to understand what a data packet is. A packet is a unit of data which travels over a network. When you provide data to the computer to be sent over a network, the data cannot be sent all at once. Therefore the data is fragmented or broken down into packets by the concerned protocol and then those packets are transmitted over the network. A packet usually contains the following:
- actual data
- details of sender
- details of receiver
- any other options related to the transmission of data
These ingredients except the actual data is bundled together into what is usually called as “header”. Different kinds of packets have different kinds of details in their header and handle data in different ways.
Now coming back to the main topic, the “connection” between the two devices (Device A which is the sender & Device B which is the receiver) over the network is established by what is called a “three way handshake” in the following manner:
- Device A sends a packet to Device B (called SYN packet – short for synchronize) to check if Device B is accepting any new connections.
- Device B sends back a packet to Device A (called SYN/ACK packet – short for synchronize/acknowledge) to tell that it is accepting new connections.
- Device A sends a packet to Device B (called ACK – short for acknowledge) packet to acknowledge that it has received the reply of Device B and will start communication shortly.
Now, after a connection is established, the actual data transfer is done.
Since your data is fragmented into packets before transmission, each of the packets sent is given a sequence number so as to identify the order of the packets. For each packet that is sent from source to destination, the destination has to acknowledge (ACK) every packet received. It may happen that a packet may be lost along the way before reaching its destination. In such cases, when the sender does not receive an ACK from the destination for certain period of time, it assumes that the packet has been lost, and re-transmits the same.
Now, when the packets reach their destination, they are reassembled as per the sequence number. It may happen that if six (06) packets are sent in sequence (i.e. 1,2,3,4,5,6), they may reach out of order at the destination (e.g. 1,2,3,6,5,4) due to network congestion or different packets taking different routes. Thus, the destination will see their sequence number and will rearrange them into correct order.
A TCP packet will also contain the checksum of the data being transmitted in the data packet. Checksum refers to a value that is derived from an underlying original data. Thus, if any of the data is corrupted in the packet, the destination will calculate the checksum of the data in the packet and compare it against the checksum sent by the sender in packet. If both the checksums match, the data is correct. If the checksums differ, the packet needs to be re-transmitted.
Another feature of TCP is that it does flow control to ensure that the destination is not overwhelmed by data. If such a situation will come into being, the destination will ignore all the packets beyond its handling capacity. TCP ensures that this does not happen by sending how much data the destination can receive (called “window size”) back to the sender in the header of the ACK packet it sends to the sender in acknowledgement of a packet received from the sender.
After data is transmitted, the connection between the two devices will need to be closed. This is done by the sender Device A by sending a FIN packet (short for finish) indicating that the data transmission is done and the sender will now like to close the connection. The destination Device B will send a FIN/ACK (short for finish/acknowledgement) to acknowledge the request. The sender Device A will then send an ACK packet to acknowledge that it has received the reply of Device B and will stop the communication.
PORTS: This TCP connection is done between Device A and Device B by using something called “ports” or “internet sockets”. The usability of port can be understood by an analogy to the ports used by ships. When something needs to be sent via ships, the material will need to be sent via ports. Thus a ship starts from a particular port and reaches its destination port. Similarly, when data needs to be sent over a computer network, it is sent via virtual addresses on the device called “ports”. Different protocols use different port numbers. Port number 0-65535 exist on TCP indicating that a device can theoretically accept 65536 TCP connections simultaneously.
For Wikipedia entry on TCP, click here.
For Wikipedia entry on Internet, click here.
For more posts on Internet, click here.
For more posts in The Cyber Cops project, click here.