It takes application layer data and. It enables more than one application to communicate simultaneously through the network and the data doesn’t get mixed. It segments data into segments so that if data lost then only that segment needs to be retransmitted. It controls data speed, if data is lost frequently then it slows down the communication. It assigns each application a port number and it is attached the segment so that the transport layer at the other end can determine which application will get the data.
The used port numbers are
Well known processes: like http, ftp etc that runs on server, 0-1023
Registered Ports: The applications that each host uses, 1024-49151
Dynamic or Private: The port number when using for initial connection, 49152-65535
When the destination device receives data at transport layer, it sees the sequence number and reassembles several segments, sees the port number and gives the data to the appropriate application layer apps.
The two common protocols are
TCP: uses sequence number, acknowledgments, flow control etc. so has large overhead usually used in application where data lost has severe effect like web pages, file transfers
UDP: connectionless, no acknowledgement, just stand and deliver. It has very low overhead so it’s best effort connection. Usually used in VOIP, or video chat.
Three way handshake:
It uses three way handshake when initializing a new connection.
Firstly, the sender sends a segment with SYN flag=1 with initial seq. number (ISN). Secondly, when the receiver gets it, it sends the transmitter a segment with ACK no= ISN+1; SYN flag=1, ACK flag=1.
Thirdly, the transmitter acknowledges a segment with SEQ=ack+1; ACK flag=1, SYN=0.