[Book Review] Beej's Guide to Network Programming
Tags: computerscience, socket, c
Published: 2024-07-13 01:38:11

## Intro - what is this book about?
Yes, I finally finished reading this book. 

As a person who has never taken a computer networking course in university, I had thought for a long time of learning that subject intensively. However, I could not find a solid university course that is open to public(something like [MIT’s introduction to algorithms](https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/)). And many of the textbooks prefixed “introduction” spent hundreds of pages explaining quite low-level concepts such as routing algorithms or even physical wires that connect the continents!

Then I found [Beej's Guide to Network Programming](https://beej.us/guide/bgnet/) that is recommended frequently on the Internet. At a glance, I found it easy to read because of the author’s way of explaining concepts in a humorous manner. But at the same time, compared to other computer network books, this book contains many code examples, so that I thought it suits more for the programmers who want practical socket programming practice. 

And after reading through all the chapters except chapter 9(because it is more like a reference for a bunch of C socket functions), I found it a good read.

## Good parts

### Friendly introduction to technical concepts
The book starts with a few basic concepts such as IP, port, and socket. However, it doesn’t go deeper into introducing very technical algorithms or physical devices used for network communications. As a developer who deals with web applications daily, I found it more relevant to my job. Even though the book sometimes mentions bits and bytes, it is still readable and you usually never do any bitwise operations while reading the C code in the book.

### Plenty of code examples
For those who want to get their hands dirty with code, this book is for you. Except for the general overview parts on computer networking, most of the explanations in the book come with code examples in C. This is particularly useful for knowing how actual network communications occur inside our web applications. For example, the [polling operation](https://beej.us/guide/bgnet/html/split/slightly-advanced-techniques.html#poll) sweeps through all the registered sockets to check whether there are incoming events to be handled.

Moreover, the examples don’t import any external libraries, so you don’t have to deal with irritating third-party dependency problems.  

## Soso parts

### Mainly focused on socket programming only
This book is very good as a friendly reference to socket programming and relevant system calls. However, it does not go “higher” or “lower”:

- "higher": Most of today’s web applications rely on the HTTP protocol. It could have been better if the book contained more explanations on this higher layer with actual running code.
- "lower": I think the book could have shown how a packet looks like using tools such as Wireshark that snatches packets generated by the examples. Introducing a few Linux/Unix commands for networking could also have been helpful for understanding how our application code interacts with the kernel.

However, I found another good resource written by the same author: [Beej's Guide to Networking Concepts](https://beej.us/guide/bgnet0/). It seems to cover many core concepts more comprehensively than this book with a lot of coding exercises. I hope this “concept” book will fill the gap of the “programming” book. 

### Not recommended for those who are not familiar with C code
If you don’t know much about C programming, this book could be overwhelming. It doesn’t explain any basic concepts such as pointers or type casting. Although we don’t suffer from dependency hell like when dealing with CMake, if you don’t know much about C then reading code would still be difficult. 

Personally I am okay with C code. However, the book could have been more beginner-friendly if it were written in Python, which has almost all the counterparts of the socket functions of C in its [socket library](https://docs.python.org/3/library/socket.html). The ["concept" book](https://beej.us/guide/bgnet0/) by the same author uses Python this time, so we can expect some fun there.

## Conclusion
Overall, the book is filled with practical code examples that are useful when understanding a network application using socket system calls. Of course, you won’t really need to use these functions when writing your own application, because many languages support their own wrappers for those "low-level" socket networking functions(Python has libraries like [socketserver](https://docs.python.org/3/library/socketserver.html) and [http](https://docs.python.org/3/library/http.html)). Nonetheless, I think once in your career as a developer you should understand what is going on behind all these highly abstracted communications using HTTPS or websocket. In that sense, this book is a good read and also a good reference.