Beej's Guide to Network Programming
A free, friendly and long-loved guide to network programming with the sockets API in C. It walks through addresses, TCP and UDP sockets, clients and servers, and handling many connections, with complete example programs. Writing even one of its examples makes the transport layer concrete in a way lectures rarely do.
Book
Other
Brian "Beej Jorgensen" Hall
Self paced
Intermediate
Free
What it is
Beej's Guide to Network Programming is a free guide to using Internet sockets, the programming interface behind every networked program. It covers IP addresses and ports, IPv4 and IPv6, the core socket calls (getaddrinfo, socket, bind, listen, accept, connect, send and recv), stream sockets for TCP, datagram sockets for UDP, blocking, and handling many connections with poll and select. It includes full example programs for clients and servers, and a reference section for the main calls. The guide is available as HTML, as a single page and in several PDF layouts, and a printed book is sold separately.
Who it is for
It is aimed at programmers who know some C and want to write networked programs, and it is widely used by university students taking a computer networks course. The examples target Unix-like systems such as Linux and macOS, with notes for Windows. If your course teaches the TCP/IP model from a textbook, this is where you turn it into working code.
Why it is worth your time
Networking courses often stay at the level of diagrams: layers, headers and handshakes. Writing a TCP echo server and client shows you what the transport layer actually gives a program: a byte stream with no message boundaries, which is why a single recv can return half a message. Writing the UDP version shows the difference in practice. That understanding is the base for building an HTTP server, debugging timeouts in a backend, or reading how a database driver talks to its server.
Tone and style
The guide is famous for its informal, humorous writing, which makes a dry API easier to follow. Under the jokes it is precise, and it has been maintained and updated for many years, including modern IPv6-ready practice with getaddrinfo.
Free or paid
Reading online or downloading the PDF is free. A print edition is available for purchase for those who prefer paper; it is not needed.
How to use it
Read the early chapters on addresses and the socket calls, then type out and run the stream server and client examples. Change them: turn the server into an echo server, then handle two clients at once. Then do the same with datagram sockets. Keep the reference section open while building a larger project, such as a small HTTP server.
Common questions
I do not know C well. Can I still use it? The concepts transfer to any language; Python's socket module uses the same calls. You may want to follow along in Python first and return to C later.
Is it up to date? The guide has been revised many times and covers IPv6 and modern address lookup. Check the version and date shown in the guide itself.
Ready to start?
Opens on Brian "Beej Jorgensen" Hall in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.