tags:

views:

1064

answers:

9

Hi all,

though I haven't worked with sockets professionally, I find them interesting. I read some part of Unix Network Programming by Richard Stevens (considered to be the Bible I suppose as it is referred by everyone I ask) but the problem is the examples require a universal header unp.h which is a PIA to use.

Can some of you suggest a good reading for socket programming in Unix/Linux? Considering I am relatively experienced C/C++ coder.

+12  A: 

The canonical reference is UNIX Network Programming by W. Richard Stevens. upn.h is really just a helper header, to make the book examples clearer - it doesn't do anything particularly magic.

To get up and running very quickly, it's hard to go past Beej's Guide To Network Programming using Internet Sockets.

caf
It has been refered by all and sundry, I am sure there are other good readings as well. Trying out its examples is a PIA. The problem I see is the headers given in the examples are wrappers for the actual functions and that is not how one learns the API. And most importantly they don't compile (atleast on my system after umpteen trials it failed repeatedly)
rocknroll
Which Linux system are you working on, then? Beej's page says Fedora Core (version 3 IIRC)...
Jonathan Leffler
+1  A: 

Here is an online tutorial on C and Linux Socket topics.

nik
+10  A: 

I used Beej's Guide to Network Programming

There's plenty of examples of client and server code with explanations at each step of the way.

temp
+1: This is a great quick-start guide. Should be plenty to get you writing your own random socket-driven apps.
ojrac
+1  A: 

APUE is a good way to familiarize you with the unix environment as well as C programming in the unix context so that you can move on to socket programming.

alok
@alok This book is already mentioned in caf's answer.
Avihu Turzion
A: 

Beyond the Stevens books already mentioned, I found the following two to be really good and relatively short reads for TCP/IP programming issues (especially gotchas and common errors):

After that, you probably want to read source code for network applications. The various linux utilities and applications are a good starting point.

ars
A: 

You can reference the paper I wrote when I taught the undergraduate computer science cource, Computer Networking Fundamentals, at ufl.edu a long time ago: "A Crash Course In Unix TCP/IP Socket Programming".

The paper is old. I'm amazed that when I Binged for it, there's still a half-dozen references to it out there.

Some of the compiler semantics and necessary header files may have changed a bit over the years, but the basics of setting up a UDP or TCP sockets and doing basic DNS stuff discussed are still valid today.

Good luck!

selbie
+2  A: 

This seems to be the classic dilemma of wading into the pool or diving head first into the deep end.

FWIW I find the Steven's wrapper code to be annoying as well and I have struggled to get at least some of the examples working on every platform I tried them on. That said the wrappers hide mostly trivial error handling that would have been repetitive, unenlightening, and taken up more space in an already large book. (Though in fairness the editors can throw out the last 1/4th of the book covering XTI to make room.)

Network programming is deep enough of a topic that you can alternate riding the surface waves and doing cannonballs. Several good sources for a quick start have been mentioned that will get you past the "wow, I got it to work" stage. But when you need to ascend to the "I need it to be robust and reliable because my job/product depends on it" stage you will come to appreciate Stevens, warts and all, for his uncanny ability to anticipate your current problem.

There have been chapters of Steven's work I successfully ignored for years. But I was sure grateful they were there when I needed them.

Duck
A: 

The UNIX Network Programming Volume 1/2, by W. Richard Stevens is legendary.

Ithilgore also wrote a very detailed document on raw sockets.

Also, Beej's Guide to Socket Programming is well written, simple to understand, and a definite recommendation.

Whatever you read, ensure you write complementing code.

blacky
A: 

You also consider the more general reference, Unix™ Systems Programming: Communication, Concurrency, and Threads By Kay A. Robbins, Steven Robbins Prentice Hall ISBN: 0-13-042411-0

still, Richard Steven's book is the most complete reference on that specific topic