This page provides a list of resources available for learning sockets programming. They include sources for compilers, books, and web sites that I have found helpful.
You can't work without your tools. Most of you reading this already have a compiler or compilers that support network programming, but in case you don't or you want try a different tool, here are some that I know of:
Linux The simple one first, because with Linux you should be set up and ready to go. Most Linux distributions come with several languages, including perl, python, ruby, and GNU's C compiler, gcc, and their associated libraries. However, if the language you want to use is not installed in your Linux machine, it could be for one of a few reasons:
- It's on your distribution CD, but the installation procedure simply did not install it. In that case, simply install it from the CD. Some, like gcc, require other support libraries to be installed as well, but the package manager will tell you about those.
- It's not on your distribution CD, but it's on a different one. I encountered this with Mandrake 7.2, which did not have gcc. It turned out that gcc was only available on their more expensive higher-end "power-user" distribution. That definitely did not make me a happy camper, but I kind of got even by picking it up at a greatly reduced clearance price.
- It's not available on any distribution. In that case, you should be able to find it on the Web and download it for free (there may be a few exceptions, but I haven't heard of one yet). In some cases, you might only get the source, in which case you will need to compile it and you will need to have gcc installed to be able to compile it.
Microsoft Obviously, if you are going to use Visual Basic, then there is only one source available. 'Nuff said about that? For C/C++, Microsoft is only one of several possible sources. I have used Visual C++ version 6 with great success, both in writing Windows and console applications. While I have not used the earlier versions of Visual C++ for writing network applications, I assume that they should be up to the task as well.
But there are two things of which you should be aware:
- Win16 vs Win32: Socket programming changed a lot in Win32, all for the better. In Win16 (e.g., Windows 3.1), most of the Winsock drivers were proprietary and worked only with their specific NIC, plus the Windows interface was cumbersome. In the last Win16 version of Visual C++ (v 1.5.2), there is a Winsock library, but I have never used it and probably never will. I'm not even sure that a Win16 Winsock application will run under Win321. Bottom line: stick with Win32.
- The Microsoft Foundation Classes (MFC) development framework includes a number of sockets classes and support function. But I have heard that the socket classes were not well-written; in "Inside Visual C++" (fourth edition, page 861), author David Kruglinski wrote that he was advised against using CAsyncSocket and CSocket for 32-bit synchronous programming and that the source code still contained "some ugly message-based code left over from Win16". I don't know if that has been corrected in the meantime, but I have never used either class and doubt that I ever will.
1 Before Windows 95, the Navy put together and distributed its Navy Internet Kit (NIK), which included several Win16 internet programs. When we started using Windows 95, we found that in order to still use the NIK, we first had to replace the new 32-bit WINSOCK.DLL with the old 16-bit version. That worked fine, except that Windows 95 in its infinite wisdom would periodically check during boot-up and, finding an older copy of a DLL, would "do us a favor" and automatically replace it with a new one. Which would prevent the NIK from working. But the worst thing about it was that it seemed to happen most often to the admiral's computer. We ended up adding a line to the AUTOEXEC.BAT file that would copy in the 16-bit Winsock DLL, thus undoing the big "favor" Windows 95 was doing us.
Borland Borland, Microsoft's old long-time nemesis, offers networking capability in their two major programming products, Delphi and C++Builder. An interesting thing about Borland is that they offer version 5.5 (Aug 2000) of their C++ compiler and command-line tools for free download; go to http://www.borland.com/products/downloads/download_cbuilder.html. I found their on-line registration a bit of a hassle and I encountered problems converting an existing Visual C++ console app that I never could resolve. Of course, it didn't help that one of the items missing from the package was the utility to convert Visual C++ makefiles over to C++Builder. But at least now I have a 32-bit version of grep, which I am very happy with.
If you're looking for a free compiler, you might consider giving them a try. You might even have better luck with it than I did.
Dev-C++ by Bloodshed Software Dev-C++ is a fairly complete IDE that uses the MinGW port of gcc to Windows. And it is free. Part of my quest was to find an inexpensive alternative to Visual C++ that I could recommend on this page and Dev-C++ is that alternative. And free is about as inexpensive as you can get. Dev-C++ allows you to do Windows programs, console apps, DLLs, and even GTK+ apps. It works fairly well, but I've encountered a few rough spots. Also, when I downloaded their stable version (version 4), I found that its package manager did not allow me to install any of the extra packages. For that capability, I needed to install their beta version, version 5.
However, since my main interest was in console apps, I never use the IDE anyway. I just put the Dev-Cpp bin directory in my search path and run gcc and make from the command line, using whatever editor I feel like (even vi). For that matter, I could just as well gone straight to MinGW, if I had known about it.
So far it works just fine. I have written a number of network applications with great success. My only complaint is that the getopt function was missing from the libraries, so I had to find some source code and make my own getopt library.
If you're wondering why it's called "Bloodshed Software", read here.
Java at Sun Sun is the developer and distributor of the Java language, which has networking support built in. As far as I know, downloads of Java are still free.
Active State ActiveState is the primary source for ports of Perl, Python, and Tcl to Win32. Downloads are free. I'm including this link because Perl and Python both offer sockets support.
Lua Lua (Portuguese for "moon") is an embeddable, extensible scripting language from Brazil that appears to have gained some popularity in games programming. I'm including this link because of LuaSocket. LuaSocket is a Lua extension library to provide TCP/IP support as well as SMTP, HTTP, and FTP. I haven't tried it yet, but it's been tested on Windows 98, Windows 2000, Linux, AIX, SunOS and IRIX.
TCP/IP Sockets in C: Practical Guide for Programmers By Michael J. Donahoo and Kenneth L. Calvert, Morgan Kaufmann Publishers, 2001, 110 pages, ISBN 1-55860-826-5, US$ 15.95
Web site: http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/
(Original Title: The Pocket Guide to TCP/IP Sockets: C Version, ISBN 1-55860-686-6, http://cs.baylor.edu/~donahoo/PocketSocket/)The authors have written a few books of the "Practical Guide" series, of which this was one. This thin book does offer the "skinny", providing a concise and clear start. They stick with echo clients and servers as their sample code, which is fine:
- The echo protocol is extremely simple and does not obscure the overall structure of the client/server with message formatting and parsing concerns.
- You can take in the entire program all at once and understand what clients and servers basically need to do.
- You immediately have a pair of tools to test the basic concepts and your TCP/IP connection.
- You have "code skeletons" (as recommended by Jon Snader -- see below) to base your own applications on.
The book's API reference is a handy tool. I keep a copy of it in my Palm. Indeed, the API reference was the main reason I had bought the book in the first place and now here I am using their examples as the basis of my own experiments.
The web site includes links between the pages for all their books (including TCP/IP Sockets in Java: Practical Guide for Programmers), the example code from the books, book errata, and some coding experiments, e.g.:
- Winsock adaptations of text code and links to Winsock tutorials, eg:
- An Acrobat Reader PDF document, Transitioning from UNIX to Windows Socket Programming by Paul O'Steen
- Listings of their books' code converted to Winsock at http://cs.baylor.edu/~donahoo/PocketSocket/winsock.html and at http://cs.ecs.baylor.edu/~donahoo/practical/CSockets/winsock.html (for the second edition)
- C++ classes to encapsulate sockets.
- The MFC sockets classes
I would recommend that you check out the pages for both of their C books. You might miss something if you don't, since the material under the one book is not duplicated under the other.
The authors also wrote a version of the book for Java, TCP/IP Sockets in Java: Practical Guide for Programmers, ISBN 1-55860-685-8, which received good reviews on Amazon.com. Its page on Amazon.com links to other books on Java network programming.
Linux Socket Programming by Example By Warren W. Gay, Que, 2000, 576 pages, ISBN 0-7897-2241-0. Sockets programming is native to the UNIX/Linux environment, where it is used for more than just TCP/IP (eg, forms of interprocess communication). This book starts with sockets basics and ends with advanced topics, with several client and server examples in between. For example, I used this book to verify my design for a broadcast client application.
The reviewers on Amazon.com gave the book a four-star rating.
Network Programming for Microsoft Windows By Anthony Jones and Jim Ohlund, Microsoft Press, 1999, 675 pages, ISBN 0-7356-0560-2. This book covers a fairly wide range of topics, mainly using Winsock but not MFC. It even gets into raw sockets (for the highly experienced only). There's a lot of material for a beginner to absorb as his first exposure to the subject. This was the first book I picked up on the subject (besides a come-up-to-speed-quick book on TCP/IP -- see below) and I intend to come back to it as I progress.
According to Amazon.com, the second edition was published in early 2002 (800 pages, ISBN 0-7356-1579-9). This edition reportedly concentrates more on sockets and on Microsoft's new whiz-bang networking services, relegating the first book's coverage of "legacy APIs" (eg, NetBIOS, Mailslots, and Named Pipes) to the CD.
Network Programming with Perl By Lincoln D. Stein, Addison-Wesley, 2001, 784 pages, ISBN: 0-2016-1571-1.
Web site: http://modperl.com:9000/perl_networking/Even though it is in Perl, the concepts and most of the functions calls are essentially the same as in C. Stein goes through several ways to design client and server applications and discusses the strengths and weaknesses of each and discusses solutions to those problems.
The only minus side that I see in this book is that it was written mainly for UNIX, so if you are going to program for the Windows environment, as is my situation, then not everything will be applicable. For example, the discussion of forking servers was of little more than academic interest for me since we cannot fork new processes under Windows (though I don't know about XP). Still, the sample programs in this book (the echo servers and clients, the daytime client, and the non-interactive telnet client) were the first that I got up and running.
BTW, on Amazon.com, all ten thoughtfully written reviews all gave the book a five-star rating.
Effective TCP/IP Programming: 44 Tips to Improve Your Network Programs By Jon Snader, Addison-Wesley, 2000, 299 pages, ISBN: 0201615894.
Web site: http://home.netcom.com/~jsnader/I haven't had time to read through it yet, but this looks like a good set of guidelines for developing networking applications, especially as I progress. His tips include understanding what the different facets of TCP/IP do (and can do for you), how to handle problems (like "rude behavior" from a peer), and what some of the troubleshooting tools are and how to use them.
Reviewers have given it high ratings on Amazon.com.
SAMS Teach Yourself TCP/IP in 24 Hours By Joe Casad and Bob Willsey, SAMS Publishing, 1998, 348 pages, ISBN 0-672-31248-4. I mention this book because it is the one that I used to acquaint myself with TCP/IP and I still keep it around to explain certain concepts to my co-workers. It is a beginner's level book and it does its job as well as most beginner's TCP/IP books would.
These books have been recommended by several sources, even though I haven't gotten around to getting any of them yet.I have read especially high praise for the late W. Richard Stevens' books and have found them in almost every sockets programming bibliography. Jon Snader even included as Tip Number 41 in his book, Effective TCP/IP Programming: 44 Tips to Improve Your Network Programs: "Tip 41: Read Stevens". Stevens' authority in the field is based in part of his having dug into the details of each protocol and having learned through practical experience what is really going on at all levels. His home page has been resurrected at http://www.kohala.com/start/.
This particular list was researched from Beej's Guide to Network Programming (see below).
- Unix Network Programming, volumes 1-2 by W. Richard Stevens, Prentice Hall. ISBNs 013490012X 46 and 0130810819 47.
- Internetworking with TCP/IP, volumes I-III by Douglas E. Comer and David L. Stevens, Prentice Hall. ISBNs 0130183806 48, 0139738436 49, and 0138487146 50.
- TCP/IP Illustrated, volumes 1-3 by W. Richard Stevens and Gary R. Wright, Addison Wesley. ISBNs 0201633469 51, 020163354X 52, and 0201634953 53.
- TCP/IP Network Administration by Craig Hunt, O’Reilly & Associates. ISBN 1565923227 54.
- Advanced Programming in the UNIX Environment by W. Richard Stevens, Addison Wesley. ISBN 0201563177 55.
Internet Requests for Comments (RFC) at the Internet Engineering Task Force (IETF) website Access to the RFC documents which are the source specifications for the Internet, TCP/IP, and all its protocols. If you are going to try to do anything with an existing protocol, you must read the applicable RFCs.
IANA -- Internet Assigned Numbers Authority This is the authority for registering IP addresses and port numbers.
Port Numbers This is the official list of assigned port numbers from IANA.
Beej's Guide to Network Programming Using Internet Sockets Good beginner's source.
Offered in several different formats, including online HTML, PostScript, and PDF.
Translated into several languages: Chinese, French, German, Korean, Romanian, Spanish
BSD Sockets: A Quick And Dirty Primer, by Jim Frost
Communication Systems - CP3340 - Advanced Systems Programming - CP3008 Has notes on sockets programming as well as on some common protocols.
TCP/IP Tutorial and Technical Overview Gets into all kinds of networks and TCP/IP application and routing protocols.
Winsock Programmer's FAQ This is the FAQ for the alt.winsock.programming and comp.os.ms-windows.programmer.tools.winsock newsgroups. It serves as a repository of Winsock programming information and links.
The UNIX Socket FAQ Almost more of a newsgroup than a FAQ. Users post their questions and other users try to help them.
Check the rules before you reveal yourself to them as a newbie.
The Ethereal Network Analyzer A free packet sniffer which runs on either UNIX/Linux or Windows.
The site also has some good links.
Return to Top of Page
Return to DWise1's Sockets Programming Page
Return to DWise1's Programming Page
Share and enjoy!
First uploaded on 2003 July 26.
Updated on 2011 July 18.