The Transport layer is the fourth layer in the OSI model. This layer’s job is to check whether the data has been delivered to the destination without any error during the transmission process.
When sending data, this layer is responsible for dividing big packets into smaller packages according some technical rule that we’ll go though later in its due time. The second job of the Transport layer is when the device is receiving data.
In this phase, it’s the Transport layer’s job again to reassemble the broken chunks of data back into one piece. This is accomplished through segment sequencing. This is done by appending a unique number to each segments.
Transport layer's relation with higher layers of the OSI
By looking at the above picture, you see that the Transport layer is depicted as a separate layer below the first group of layers. The reality is that the Transport layer has a very close relationship with the higher layers (Session, Presentation and application) to deliver and receive data without error.
One of the important duties of this layer is to add port number to the data packets. As you know, the Network layer adds logical address (IP) to the data and the job of this address is to only specify the receiver in the network. Beside IP address, a port number is also needed to address the service that this packet is destined to reach.
The reason is that a packet which is originally intended to reach a web application must not be delivered to an accounting application. For example. the Transport layer by default adds the port number 80 to all packets that are going to reach a web interface. Although without a port number, the packet reaches the destination but the receiving machine won’t be able to determine which program or service needs to get this packet.
The connection type
To provide a error-free connection and to properly control the flow of data, protocols at the Transport layer use two types of mechanisms to send data:
Connection-oriented: In this method services use acknowledgments and responses to establish a virtual connection between sending and receiving stations. The acknowledgments are also used to ensure that the connection is maintained. Connection-oriented communications are similar to phone calls.
Imagine you dial the recipient’s number. He picks up and says hello. You then introduce yourself and say you’d like to talk about something, and the conversation begins. If you hear silence for a while, you might ask “Are you still there?” because you want to make sure the recipient is still on the line. So for every message you send, you expect to hear something as “acknowledgment”. The same way, when you want to finish the conversation, you both agree to end the conversation and then you end the connection by hanging up.
Connection-oriented services work the same way, except that instead of phones, and words, they use NICs, and special packets. This procedure is known as TCP connection in a computer network.
Connection less: Unlike connection-oriented mechanism, this method doesn’t have mechanism to detect errors or to control the flow of data. But they do have one simple advantage; and that’s higher speed in transmission.
Because in connection-less method, the sending machine doesn’t care or wait to receive acknowledgment for each segment, there is no delay between the operations and thus, the speed is higher compared to connection-oriented mechanism.