Programs on different machines need to talk to each other.
You’ve learned how to use I/O to communicate with files and how processes on the same machine can communicate with each other. Now you’re going to reach out to the rest of the world, and learn how to write C programs that can talk to other programs across the network and across the world. By the end of this chapter, you’ll be able to create programs that behave as servers and programs that behave as clients.
C is used to write most of the low-level networking code on the Internet. Most networked applications need two separate programs: a server and a client.
You’re going to build a server in C that tells jokes over the Internet. You’ll be able to start the server on one machine like this:
Other than telling you it’s running, the server won’t display
anything else on the screen. However, if you open a second console,
you’ll be able to connect to the server using a client program called
telnet. Telnet takes two parameters:
the address of the server, and the
port the server is running on. If you are running
telnet on the same machine as the server, you can use
for the address:
You’ll be using telnet quite a lot ...