Basic Winsock Example Programs

These examples show you how to implement several basic kinds of client and server programs. All the client programs simply connect to an echo server, send a packet of data, read the echoed reply back from the server, check that the data in the reply packet is what was sent, and exit. The server programs implement various forms of the echo server idea. (You can also use a standard "port 7" echo server available as an option on many UNIX boxes and Windows NT.) The echo server idea lets us focus more on the structure of the program and less on its function, and yet still provide a fairly functional program.

Although these programs are "minimal" in the sense that they don't do much, they are still complete in that they do all the proper error checking, shut their connections down gracefully, are fully commented, etc. These programs are also well-structured: all of the programs have a "layered" design, with each layer interfering as little as possible with neighboring layers. This makes it easy for you to transplant useful code from these programs into your own projects.

These programs all follow the same form as much as possible. Any time you find two functions named the same in two different examples, you can be sure that they have the same function, so you can study them comparatively. For example, you can study EstablishConnection in the basic and asynchronous clients to see how "going asynch" changes the way you handle a connection attempt.

Right now, I only have one simple client and one simple server here, but more are soon to come, as I find the time. The next program will be a multi-connection multithreaded server, and then a select()-based server. After that, I'll implement asynchronous clients and servers with straight Win32 API code. Next will come overlapped I/O clients and servers. After that, reader comments will guide me. Two other ideas I have in mind are examples that use I/O completion ports and the MFC CSocket/CAsyncSocket classes. I may even present an example that uses my Endpoint class library.

Support Files

You should probably download all of these before you begin, because all examples require at least one of these files.

The Examples

These are the main example files. Each example comes in a single file; the header comment in that file tells you which other modules it requires.

Each of these examples illustrates a particular design choice. You can find answers on "which choice is better" for a given application in Tutorial 1. Obviously, no one design choice is best for all situations, or we would not have so many choices. Between the Tutorial's advice and these concrete examples, you should be able to make your decision fairly easily.

Back to main Examples page...


Go to my home page Go to my Important RFC Lists page Go to the main Programming Resources page

Please send updates and corrections to <tangent@cyberport.com>.