30.2 TCP Client Alternatives
We have already examined various client designs, but it is worth summarizing their strengths and weaknesses:
Figure 5.5 was the basic TCP client. There were two problems with this program. First, while it is blocked awaiting user input, it does not see network events such as the peer closing the connection. Additionally, it operates in a stop-and-wait mode, making it inefficient for batch processing. Figure 6.9 was the next iteration, and by using select, the client was notified of network events while waiting for user input. However, this program did not handle batch mode correctly. Figure 6.13 corrected this problem by using the shutdown function. Figure 16.3 began the presentation of our client using nonblocking I/O. The first of our clients that went beyond the single-process, single-thread design was Figure 16.10, which used fork with one process handling the client-to-server data and the other process handling the server-to-client data. Figure 26.2 used two threads instead of two processes.
At the end of Section 16.2, we summarized the timing differences between these various versions. As we noted there, although the nonblocking I/O version was the fastest, the code was more complex and using either two processes or two threads simplifies the code.
|