 Hello and welcome to this session on communication using TCP. At the end of this session, students will be able to introduce client server connection oriented concurrent communication using the service of TCP. Here you can see the simple flow diagram for communication using TCP. The server process The server process starts first, then it calls the socket function to create a socket. This socket is only used during connection establishment. The server process then calls the bind function to bind this connection to the socket address of the server. The server program then calls the accept function. This function is a blocking function. When it is called, it is blocked until the TCP receives a connection request from a client. A connection request is syn segment that is synchronization segment. The accept function is unblocked and creates a socket called the connect socket that includes the socket address of the client that sent the syn segment. After the accept function is unblocked, the server knows that the client needs its service and to provide the concurrency, the server process calls the fork function and the process called the fork function called as parent process. This function creates a new process called child process which exactly same as the parent process. After calling the fork function, the two processes are running concurrently but each can do different things. Each process now has two sockets, listen and connect socket. The child process is now ready to serve the client. The receive function like the receive from function is blocking the simple possible one. The server may use other functions to receive and send data, choosing one is appropriate for the particular application. Here we assume that the size of the data to be sent to the client is so small that can be fit into a one single segment, otherwise here we need a loop to repeatedly call the send function. The server may send data using one single call to send function, TCP may use several segments to send the data. Now client process. The client process is simple. The client calls the socket function to create a socket, it then calls the connect function to request connection to the server. The connect function is blocking function, it is blocked until the connection is established between two TCP's. When the connect function returns the client calls the send function sent to data to the server. Here we use one call to send function. Assuming that the data can be sent with one call based on the type of application. The client then calls the receive function which is blocked until the segment arrives and the data are delivered to the process by TCP. Here although the data are sent by the server to one single call to the send function, the TCP at the server side may how use several segments to send data. This means that we need to call the receive function repeatedly to receive all data. The loop can be controlled by the return value of the receive function. The status of parent child process. Here in the figure you can see the status of the parent child process with respect to the sockets. So in part A in the figure shows the status before the accept function returns. The parent process uses the listen socket to wait for the request from the client. When the accept function is blocked and returned which is shown in this part B, the parent process has two sockets, the listen and the connect sockets. The client is connected to the connect socket after calling the fork function that is shown in part C. Here we have two processes each with two sockets. The client is connected to both the processes. The parent needs to close its connect socket to free itself from the client and be free to listen to request from other clients that is shown in part B. Before the child can start serving the connected client it needs to close its listen socket so that the future request does not affect it that is shown in part E. So here in part F finally when a child finishes servicing finally when the child finishes serving the connected client it needs to close its connect socket and to disassociate itself from the client that has been served. Now here variables use in eco-client and eco-server using TCP. Now you can see here the variables use in eco-client and eco-server using TCP. So here in this particular diagram the variable used by the client process. So the variables bytes to receive then n file descriptor the server length then server address length then receive buffer. So from here the data is to be taken and the send buffer and here you can see the pointer start of the buffer and the pointer moving towards the send buffer. Here you can see the variable use in the client process. The bytes to receive then the number n then file descriptor and the server length and the the receive buffer and send buffer. Now here in this particular diagram you can see the variables used by the server process. The number n then the connect file descriptor listen file descriptor bytes to receive then server length client length and the process ID. So server address length client address length and the buffer. Here the first buffer is fixed and always points to the beginning of the buffer but the second buffer is moving to the arrived bytes be appended to the end of the previous section. Here you can see the server program and eco-server that uses the services of TCP. So here every time the receive function is unblocked and it gets some data and store it at the end of the buffer. The move pointer is then moved to point the location where the next data chunk should be stored which is shown in the line 39. The number of bytes to read is also decremented from the original values which is shown in line 26 to prevent the overflow in the buffer at line 40. After all data have been received the server calls the send function to send them to the client. So here we know that there is only one send call but the TCP may send data in several segments. The child process then calls the close function to destroy the connect socket. Here you can see the client program for the eco process. The client program uses the same strategy which we have discussed in the previous slide in the server program. The program then gets the string to be echoed from the keyboard, stores it in send buffer and sends it but the result may come in different segments. The program use a loop and repeat calling the receive function until all data arrives. Here pause the video, think and answer. The answer is B. Here is my reference. Thank you.