
Beej's Guide to Network Programming (2012) - hikz
http://beej.us/guide/bgnet/output/html/multipage/index.html
======
nilliams
Once upon a time (about 7 years ago) Beej's guides saved my life at work when
trying to implement network stuff in C for a project at work I was in over my
head on.

If there was more stuff like this in C-land I probably wouldn't have been
clambering to get away from C and into more nurturing, sharing communities at
the first opportunity.

Really cool to see he's keeping it up to date.

~~~
giancarlostoro
Another relevant / extensive source is Unix Network Programming by W. Richard
Stevens. Mostly relevant to Linux / Unix systems, but still worth a read.

Edit:

Matter of fact he lists it as the first reference under "More References"

~~~
easytiger
It is the best book, but i do hate that he uses his own wrappers, that kills
the code samples in my use cases

------
ndesaulniers
Definitely a great read, one I recommend frequently. Nowadays, I reach for
ASIO. I think I read yesterday it's going to be included in C++17? Much more
portable than POSIX sockets. After reading this I implemented a multithreaded
version [0], then started contributing to h2o [1].

[0] [https://github.com/nickdesaulniers/c-http-
server/blob/master...](https://github.com/nickdesaulniers/c-http-
server/blob/master/threaded.c)

[1] [https://github.com/h2o/h2o](https://github.com/h2o/h2o)

------
_cbdev
Definitely a great and very instructive read, and one of the few to include
IPv6 and the correct usage of getaddrinfo.

It's the guide I recommend to everyone who wants to learn about network
programming in C. I actually purchased the (slightly expensive) printed
version and never regretted it :)

[http://www.lulu.com/shop/brian-hall/beejs-guide-to-
network-p...](http://www.lulu.com/shop/brian-hall/beejs-guide-to-network-
programming/paperback/product-18179133.html)

~~~
moron4hire
Why is $20 "slightly expensive" for this book? Or was it not $20 when you
bought it?

~~~
_cbdev
Adding Shipping Costs to Germany bumps the price to about 22 USD (currently,
21EUR is what the receipt says). Considering the number of pages in this book
in relation to its price, it is slightly expensive compared to your average
"normal" book.

When comparing to other education text books though I'd not be able to
complain. Neither am I, as I still think it was worth it, if just to support
the author and to have an addition to the bookshelf.

------
mustapha
I think there are better (more correctly written) guides to network
programming, i.e., UNIX Network Programming (old, but the newest volume: The
Sockets Networking API - was written in 2003), and TCP/IP Illustrated (also
most recently updated with a 2nd edition in 2011) by the late, great W.
Richard Stevens - despite his sole work being horribly out of date, with later
volumes being worked on by Bill Fenner and Andy Rudoff, I would honestly look
no further in lieu of socket programming in C.

~~~
fyrabanks
More formal and comprehensive, absolutely. If you want something that's more
friendly to neophytes, Beej's guide is the way to go. It's quite literally
what they used in my upper div intro to Networking course at UCLA years ago.

~~~
justin66
A book that splits the difference very well is _The Linux Programming
Interface_ by Kerrisk. When I did network programming in class I leaned on it
at least as much as Stevens.

It's a great book for all kinds of stuff, too, not just network programming.

~~~
mustapha
Agreed.

------
dugmartin
This site plus Stevens' book were my goto resources in the 90's for Unix
network programming.

~~~
sspies
+1 for Unix Network Programming. [http://www.amazon.com/UNIX-Network-
Programming-Richard-Steve...](http://www.amazon.com/UNIX-Network-Programming-
Richard-Stevens/dp/0139498761)

------
devnonymous
Not just the Network Programming guide, all of beej's guides are pretty
awesome -- Specific purpose and very readable (even for non-native english
speakers).

[http://beej.us/guide/](http://beej.us/guide/)

------
christianbryant
Wow, I haven't looked at Beej in a long time. Everything's cleaner and even
more useful for entry-level consumption. When I saw the link I first thought
"boy, that's an oldie but goodie" but the 2012 really was accurate. Keep this
in circulation. He deserves the kudos and the audience.

------
de_wq912AesppE5
Back in college I wrote this address on the board and told fellow students
that this was a good site to learn some C basics and learn network
programming. Most people just laughed at the name, but I like to think Beej
helped some people who decided to check it out.

------
sporkenfang
Why can't (more) textbooks be written like this? There's no need to make CS
dry -- as long as the technical details are correct, it can and should be fun
to follow the work.

~~~
ekr
Well, maybe it's about taste. But I personally can't stand these kind of
books. Take this paragraph for example:

> What's this? There are two types of Internet sockets? Yes. Well, no. I'm
> lying. There are more, but I didn't want to scare you. I'm only going to
> talk about two types here. Except for this sentence, where I'm going to tell
> you that "Raw Sockets" are also very powerful and you should look them up.

There are quite a few books written like this, including most online
tutorials, and other resources.

What I don't like about it is that more than 50% of the content is filled with
the author's anecdotes (some of them have better sense of humor than others),
while the actual content being discussed is barely touched.

You'll never see this kind of content on advanced mathematics, or field that
require intense concentration, advanced thinking, because it's difficult to
switch the context of your thinking from the author's silly jokes to the
actual thing you're trying to learn.

In this case, it's simply touching the very simple bsd socket api, so of
course it's very easy to follow. But imagine that you removed all the
unnecessary jokes and anecdotes, you'd end up with 50% of the text and 100% of
the useful information. I'm pretty sure information density is a good quality
to have for any piece of writing.

~~~
sporkenfang
To compare to one of those advanced mathematics textbooks you're making an
example of, D&F is one of the canonical texts for an introductory graduate
algebra course, but it is one of the least user-friendly works I've come
across on the topic (I own 3-4 other graduate algebra texts at various levels,
printed in various decades, and I found it probably most difficult to wade
through, of all of them).

Note that this is merely an example and not a personal attack on the authors
or something. Having to re-read a chunk of text 5-10 times on average to
extract pertinent information is something I really don't enjoy; I don't
usually have to do it with journal/conference papers (usually 2x is enough to
grasp the details of the idea being presented) or with other textbooks.

I would rather the information being presented be somewhat 'spaced out' to
give my brain time to process it without having to go back over it. Having to
re-read a denser text takes rather longer, imo, than having to read text with
slightly less dense content just once or twice.

So, yes, it is likely a matter of taste. But my point was, I suppose, that
information presented in a dense manner takes rather longer to digest.

Beej (despite numerous anecdotes and so on) manages to present his information
in a straightforward fashion that doesn't require multiple readings to grasp.
Algebra could also be presented in a similar (if probably less jokey) fashion.
A lower amount of entropy per sentence means I have to do less work just to
get through the explanations and can spend more time on working through the
examples. Given that the time I have to spend studying is finite, a more
direct approach to explaining material before letting a student practice does
seem more efficient.

That's why I like this tutorial. It doesn't take itself seriously, which is
rather more approachable than some works, and the pertinent information is
directly presented but not in such a way that I have to re-re-re...-re read to
grasp the details.

~~~
ta0967
authors struggle for correctness and preciseness of thought and words; very
few achieve clarity of either.

there are authors whose works demonstrate possibility of high-quality
textbooks in absense of any "qutesy" or other noise.

your and GP's post show that different information passing styles suit
different people differently.

------
edsiper2
This guide was very helpful around 2001-... to build Monkey HTTP Server:

[http://monkey-project.com](http://monkey-project.com)
[http://github.com/monkey/monkey](http://github.com/monkey/monkey)

~~~
acadien
Haha! I remember using Beej's guide to get me through networking and
distributed computing back in college. The courses weren't terribly useful,
but Beej covered the practical side of it quite nicely.

------
GoodIntentions
This thing helped me with networking immensely in college. Nice to see it
still exists.

------
Blackthorn
This guide was how I learned the Posix networking APIs so long ago. Thanks,
Beej!

------
cyphax
I read this guide, used it only a few years back when I wanted to learn more
about network programming. It's a very well written guide. Certainly a great
way to learn about network programming!

------
____miah
Same boat with most of you guys, Beej's site is really interesting, not just
this one. Glad that it is still up and running. +1

------
pyre
Definitely remember reading this helping me through C sockets in University
circa 2001~2002.

