Chapter 11. Sockets and Networking: Thereâs no place like 127.0.0.1
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.
The Internet knock-knock server
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 127.0.0.1
for the address:
Watch it!
Youâll be using ...
Get Head First C 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.