Connection-Oriented Multiplexing and Demultiplexing

Connection-Oriented Multiplexing and Demultiplexing

To understand TCP demultiplexing, we have to study TCP sockets and TCP connection establishment. One slight difference between a TCP socket and a UDP socket is that a TCP socket is identified by a four-tuple: (source IP address, source port number, destination IP address, destination port number). In this way, when a TCP segment arrives from the network to a host, the host uses all four values to direct (demultiplex) the segment to the proper socket. Particularly, and in contrast with UDP, two arriving TCP segments with different source IP

The inversion of source and destination port numbers

addresses or source port numbers will (with the exception of a TCP segment carrying the original connection-establishment request) be directed to two different sockets. To get further insight, let's re-examine the TCP client-server programming example in "Socket Programming with TCP":

● The TCPserver application has a "welcoming socket" which waits for connection-establishment requests from TCP clients (see "Socket Programming with TCP" Figure 2) on port number 6789.

● The TCP client generates a connection-establishment segment with the line

Socket clientSocket = new Socket ("serverHostName" , 6789) ;

● A connection-establishment request is nothing more than a TCP segment with destination port number 6789 and a special connection-establishment bit set in the TCP header (discussed in "Connection-Oriented Transport: TCP"). The segment also contains a source port number, which was chosen by the client. The line above also creates a TCP socket for the client process, through which data can enter and leave the client process.

● When the host operating system of the computer running the server process receives the incoming connection-request segment with destination port 6789, it locates the server process that is waiting to accept a connection on port number 6789. The server process then creates a new socket:

Socket connectionSocket = welcomeSocket.accept ( );

Also, the transport layer at the server notes the following four values in the connection-request segment: (1) the source port number in the segment, (2) the IP address of the source host, (3) the destination port number in the segment, and (4) its own IP address. The newly created connection socket is identified by these four values; all subsequently arriving segments whose source port, source IP address, destination port and destination IP address match these four values will be demultiplexed to this socket. With the TCP connection now in place, the client and server can now send data to each other.

The server host may support many simultaneous TCP sockets, with each socket attached to a process, and with each socket identified by its own four-tuple. When a TCP segment arrives at the host, all four fields (source IP address, source port, destination IP address, destination port) are used to direct (demultiplex) the segment to the appropriate socket.


Port Scanning

Two clients using the same destination port number           

The situation is demonstrated in Figure 2, in which Host C initiates two HTTP sessions to server B, and Host A initiates one HTTP session to B. Hosts A and C and server B each have their own unique IP address - A, C, and B, respectively. Host C assigns two different source port numbers (26145 and 7532) to its two HTTP connections. Because Host A is choosing source port numbers independently of C, it might also allocate a source port of 26145 to its HTTP connection. But this is not a problem - server B will still be able to correctly demultiplex the two connections having the same source port number, since the two connections have different source IP addresses.

Web Servers and TCP


Before we close this discussion, it's informative to say a few additional words about Web servers and how they use port numbers. Take a look at a host running a Web server, such as an Apache Web server, on port 80. When clients (for instance, browsers) send segments to the server, all segments will have destination port 80. Particularly, both the initial connection-establishment segments and the segments carrying HTTP request messages will have destination port 80. As we have just explained, the server distinguishes the segments from the different clients using source IP addresses and source port numbers.

Figure 2 shows a Web server that spawns a new process for each connection. As shown in Figure 2, each of these processes has its own connection socket through which HTTP requests arrive and HTTP responses are sent. We mention, on the other hand, that there is not always a one-to-one correspondence between connection sockets and processes. In reality, today's high-performing Web servers frequently use only one process, and create a new thread with a new connection socket for each new client connection. (A thread can be viewed as a lightweight subprocess). For a Web server, at any given time there may be many connection sockets (with different identifiers) attached to the same process.

If the client and server are using persistent HTTP, then throughout the duration of the persistent connection the client and server exchange HTTP messages via the same server socket. However, if the client and server use non-persistent HTTP, then a new TCP connection is created and closed for every request/response, and hence a new socket is created and later closed for every request/response. This frequent creating and closing of sockets can severely impact the performance of a busy Web server (although a number of operating system tricks can be used to mitigate the problem). Readers interested in the operating system issues surrounding persistent and non-persistent HTTP are encouraged to see (Nielsen 1997; Nahum 2002].

As we've discussed transport-layer multiplexing and demultiplexing, let's move on and discuss one of the Internet's transport protocols, UDP. In the next section we'll see that UDP adds little more to the network-layer protocol than a multiplexing/demultiplexing service.


Tags

tcp sockets, udp socket, host, segments

Copy Right

The contents available on this website are copyrighted by TechPlus unless otherwise indicated. All rights are reserved by TechPlus, and content may not be reproduced, published, or transferred in any form or by any means, except with the prior written permission of TechPlus.