Everyone referred to it as Socket Programming or Network Programming in C and we started using it by using by including sys/socket.h & netinet/in.h. We thought it was 100% true. But question raised in my mind when I saw this book
Internetworking With TCP/IP Volume III: Client-Server Programming and Applications, which was available in 4 different versions
- Linux/POSIX Sockets
- AT&T TLI (Transport Layer Interface) Sockets
- BSD (Berkeley) sockets
- Window Sockets
I’m confused. This clearly shows that there is no standard for Socket API.
also I’m surprised to see sys/socket.h & netinet/in.h which are part of POSIX C library in the http://en.wikipedia.org/wiki/Berkeley_sockets . I’m more confused now.
- Why isn’t there a standard for this?
- What more socket APIs are available?
- What are the differences between each of these Socket API?
- When People say Just “Network Programming in C” / “Socket Programming” what exactly they are referring to?
- Links for any further information?
The de facto standard is BSD sockets, upon which the Linux, POSIX and Windows sockets APIs are based.
Nothing that’s still widely used. Before BSD sockets and its derivatives took over the world, there were many. Most of the ones that remain are probably in the embedded world, and even those are going away as mainstream OSes continue to swallow more and more of the embedded market.
This battle was pretty much fought and over by the mid 90’s. BSD sockets won.
There are minor differences among the BSD, Linux and POSIX variants, nothing more serious than any other differences among Unixy operating systems.
The reason they have a Linux/POSIX version of the book probably has more to do with marketing than anything technical. It answers a question the publisher probably saw a lot, “Why do I need a BSD book, I’m running Linux, not BSD!” Or, more commonly these days: “What’s BSD?”
From a 10,000 foot view, Winsock is very different from BSD sockets, but because it’s a fairly strict superset of BSD sockets, you can still move your knowledge over. Most of the differences are pure extensions to BSD sockets, mostly to do with the differences in the Windows kernel architecture and the way Windows programs are typically built. For instance, the first really big extension was asynchronous sockets, which makes it much easier to use sockets in a single-threaded Windows GUI program than using pure BSD sockets. Later extensions support special features available in the NT derived kernels that have no simple analog in Unixy systems, like event objects and overlapped I/O.
For what it’s worth, there are extensions to plain old BSD sockets in some Unixy systems, too, like the
aio_*()stuff in Solaris and other systems.If your program has to be source compatible with many systems, you either ignore these differences and program to the common base shared by all these systems, or you build some kind of translation layer that lets you use platform features transparently. Apache does the latter for instance, making use of the fastest networking features on each platform, while the core web server code doesn’t care exactly how the networking gets done. Many other programs choose the portable path, since they’re not performance critical, and saving programmer time is therefore more important.
BSD sockets or some variant.
The Winsock Programmer’s FAQ. Specifically, you might want to look at its resources section, and the FAQ article BSD Sockets Compatibility.
(Disclaimer: I’m the FAQ’s maintainer.)