The HTTP server

In this chapter, we are going to implement an HTTP web server that can serve static files from a local directory. HTTP is a text-based client-server protocol that uses the Transmission Control Protocol (TCP).

When implementing our HTTP server, we need to support multiple, simultaneous connections from many clients at once. Each received HTTP Request needs to be parsed, and our server needs to reply with the proper HTTP Response. This HTTP Response should include the requested file if possible.

Consider the HTTP transaction illustrated in the following diagram:

In the preceding diagram, the client is requesting /document.htm ...

Get Hands-On Network Programming with 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.