Chapter 5. TCP Client/Server Example

Introduction

We will now use the elementary functions from the previous chapter to write a complete TCP client/server example. Our simple example is an echo server that performs the following steps:

  1. The client reads a line of text from its standard input and writes the line to the server.

  2. The server reads the line from its network input and echoes the line back to the client.

  3. The client reads the echoed line and prints it on its standard output.

Figure 5.1 depicts this simple client/server along with the functions used for input and output.

Simple echo client and server.

Figure 5.1. Simple echo client and server.

We show two arrows between the client ...

Get The Sockets Networking API: UNIX® Network Programming Volume 1, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.