30.11 TCP Prethreaded Server, per-Thread accept


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.



UNIX Network Programming Volume 1, Third Edition
Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition)
ISBN: 0131411551
EAN: 2147483647
Year: 2003
Pages: 441

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net