Multiplexing and De-multiplexing are the two very important functions that are performed by Transport Layer.
Transport Layer at the sender side receives data from different Applications, encapsulates every packet with a Transport Layer header and pass it on to the underlying Network Layer. This job of the transport layer is known as Multiplexing.
At the receiver’s side, the transport gathers the data, examines it socket and passes the data to the correct Application. This is known as De-Multiplexing.
Sockets are the door between Transport and Application Layer. If you want to read about socket, visit this. Socket. Let us take a very simple example that will make you clear about all these terms.
Suppose that there are two houses. One is in India and Other is in America. In the house in India, lives a person James along with his 5 children. And in the house in America, lives a person Steve along with his 4 children. Now all 5 children of James write a letter to every child of Steve on every Sunday. Therefore a total number of letters will be 20. Thus, all the children write the letter, put them in envelopes and hand it to James. Then James writes source house address and the destination house address on the envelope and gives it to the postal service of India.
Now the postal service of India puts some other addresses corresponding to the country and delivers it to the America Postal Service. The American Postal sees the destination address on the envelopes and will deliver those 20 letters to the Steve House. Steve collects the letter from the postman and after considering the name of his respective children on the envelopes, he gives the letter to each of them.
In this example, we have processes and the layers. Let me explain.
Processes = children
Application Layer Messages = envelopes
Hosts = The two Houses
Transport Layer Protocol = James and Steve
Network Layer protocol = Postal Service
When James collects all the letters from his children, he multiplexes all and encapsulates them with the respective children name on the letter and house address and give it to the Indian postal service.
On the receiving side, Steve collects all the letters from postal service of America and de-multiplexes them to see, which letter is for which child and delivers it respectively.
Now I hope, you must be clear with the Multiplexing and De-Multiplexing procedures of Transport Layer.
Now you must be thinking that how the Transport layer come to know, to which socket , the packet has to be passed. So, I should help you with this confusion also. This job is done by the Source Port Number and the Destination Port Number. As every Application has been given a particular port number.
Port Numbers are 16-bit numbers. Therefore, there can be total 2^16 i.e. 65535 port numbers , starting from 0. The first 0 to 1023 port numbers are reserved for certain dedicated Applications such as HTTP, FTP, E-mail etc. If you develop a new Application, then you must necessarily provide it with a post number.