In Chapter 8, we learn how to act as a client in a
TCP connection. A TCP client initiates the connection with remote
hosts. In this chapter, we learn how to serve these connections,
accepting requests from remote hosts and we update
FtpView to serve the FTP data connection.
The FTP data connection is used to exchange files and directory listings. These exchanges involve large amounts of data. In this chapter, we examine ways to handle this data efficiently.
Before we dive into the details of acting as a connection server for TCP sockets, let’s revisit the three-way handshake. The sequence of events in this handshake is illustrated in Figure 11-1.
Figure 11-1. TCP three-way handshake event sequence
First, the connection server opens a socket and binds it to a specific address and port number. Then the server puts the socket into passive listening mode. This tells the protocol stack to accept connection requests addressed to this socket. The protocol stack sets up two queues for incoming requests, one for incomplete connection requests and one for completed ones.
A connection request arrives as an
SYN segment. The TCP server responds with
ACK segment, and sends a
SYN segment of its own. The connection request is moved to the uncompleted connection queue. When the TCP server receives an acknowledgment from the client, ...