Chapter 9’s FtpView performs the entire login process during a single event. While we are logging in, the device is unresponsive and appears dead. The same thing happens during logout. By implementing the FTP session as a state machine, we can perform operations such as login or logout as a series of small steps, executed over multiple events.
FtpView supports the Login and Logout operations. These operations can be divided into a set of transactions. We define a transaction as the exchange of a command from the client and a response from the server. We treat Connect and Disconnect as special commands, during which we call a function instead of sending a command.
The Login operation connects the session to an FTP server and logs on to that server. This operation is a sequence of three transactions: Connect, User, and Password. This sequence is illustrated in Figure 10-1.
Figure 10-1. FTP login transactions
In Figure 10-1, we see the session starts inactive and disconnected. The Connect transaction establishes the socket connection with the server. The User transaction sends the user ID and the Password transaction sends the password. If an error occurs at any point, the socket connection is closed and the session returns to inactive and disconnected. If these transactions succeed, the session ends up inactive ...